2022-06-17 12:36:21 +02:00
|
|
|
import { defineConfig } from 'vite';
|
|
|
|
import ViteReact from '@vitejs/plugin-react';
|
|
|
|
import ViteLegacy from '@vitejs/plugin-legacy';
|
|
|
|
import FullReload from 'vite-plugin-full-reload';
|
|
|
|
import RubyPlugin from 'vite-plugin-ruby';
|
|
|
|
|
2022-06-23 11:47:59 +02:00
|
|
|
const plugins = [
|
|
|
|
RubyPlugin(),
|
|
|
|
ViteReact({
|
|
|
|
parserPlugins: ['classProperties', 'classPrivateProperties'],
|
|
|
|
jsxRuntime: 'classic'
|
|
|
|
}),
|
|
|
|
FullReload(['config/routes.rb', 'app/views/**/*'], { delay: 200 })
|
|
|
|
];
|
|
|
|
|
|
|
|
if (shouldBuildLegacy()) {
|
|
|
|
plugins.push(
|
2022-06-17 12:36:21 +02:00
|
|
|
ViteLegacy({
|
|
|
|
targets: [
|
|
|
|
'defaults',
|
|
|
|
'Chrome >= 50',
|
|
|
|
'Edge >= 14',
|
|
|
|
'Firefox >= 50',
|
|
|
|
'Opera >= 40',
|
|
|
|
'Safari >= 8',
|
|
|
|
'iOS >= 8',
|
|
|
|
'IE >= 11'
|
|
|
|
],
|
|
|
|
additionalLegacyPolyfills: [
|
|
|
|
'@stimulus/polyfills',
|
|
|
|
'@webcomponents/custom-elements',
|
|
|
|
'@webcomponents/template',
|
|
|
|
'event-target-polyfill',
|
|
|
|
'formdata-polyfill',
|
|
|
|
'intersection-observer',
|
|
|
|
'regenerator-runtime/runtime',
|
|
|
|
'whatwg-fetch',
|
|
|
|
'yet-another-abortcontroller-polyfill'
|
|
|
|
]
|
|
|
|
})
|
2022-06-23 11:47:59 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
resolve: { alias: { '@utils': '/shared/utils.ts' } },
|
|
|
|
build: {
|
|
|
|
sourcemap: true,
|
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
|
|
|
manualChunks(id) {
|
|
|
|
if (id.match('maplibre') || id.match('mapbox')) {
|
|
|
|
return 'maplibre';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
plugins
|
2022-06-17 12:36:21 +02:00
|
|
|
});
|
2022-06-23 11:47:59 +02:00
|
|
|
|
|
|
|
function shouldBuildLegacy() {
|
|
|
|
if (process.env.VITE_LEGACY == 'disabled') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
process.env.RAILS_ENV == 'production' ||
|
|
|
|
process.env.VITE_LEGACY == 'enabled'
|
|
|
|
);
|
|
|
|
}
|