diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5a7a9872a..518ed3147 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -181,4 +181,12 @@ module ApplicationHelper def show_outdated_browser_banner? !supported_browser? && !has_dismissed_outdated_browser_banner? end + + def vite_legacy? + if ENV['VITE_LEGACY'] == 'disabled' + false + else + Rails.env.production? || ENV['VITE_LEGACY'] == 'enabled' + end + end end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 53d9160f4..e7507be09 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -43,7 +43,8 @@ - if content_for?(:footer) = content_for(:footer) - = vite_legacy_javascript_tag 'application' + - if vite_legacy? + = vite_legacy_javascript_tag 'application' = yield :charts_js diff --git a/config/env.example.optional b/config/env.example.optional index 6260df964..e37733a8b 100644 --- a/config/env.example.optional +++ b/config/env.example.optional @@ -133,3 +133,7 @@ SENDINBLUE_BALANCING_VALUE="50" DOLIST_BALANCING_VALUE="50" # Used only by a migration to choose your default regarding procedure archive dossiers after duree_conservation_dossiers_dans_ds # DEFAULT_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED=true + +# Enable vite legacy build (IE11). Legacy build is used in production (except if set to "disabled"). +# You might want to enable it in other environements for testing. Build time will be greatly impacted. +VITE_LEGACY="" diff --git a/vite.config.ts b/vite.config.ts index 635ebe782..c1eefb422 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,27 +4,17 @@ import ViteLegacy from '@vitejs/plugin-legacy'; import FullReload from 'vite-plugin-full-reload'; import RubyPlugin from 'vite-plugin-ruby'; -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: [ - RubyPlugin(), - ViteReact({ - parserPlugins: ['classProperties', 'classPrivateProperties'], - jsxRuntime: 'classic' - }), - FullReload(['config/routes.rb', 'app/views/**/*'], { delay: 200 }), +const plugins = [ + RubyPlugin(), + ViteReact({ + parserPlugins: ['classProperties', 'classPrivateProperties'], + jsxRuntime: 'classic' + }), + FullReload(['config/routes.rb', 'app/views/**/*'], { delay: 200 }) +]; + +if (shouldBuildLegacy()) { + plugins.push( ViteLegacy({ targets: [ 'defaults', @@ -48,5 +38,32 @@ export default defineConfig({ 'yet-another-abortcontroller-polyfill' ] }) - ] + ); +} + +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 }); + +function shouldBuildLegacy() { + if (process.env.VITE_LEGACY == 'disabled') { + return false; + } + return ( + process.env.RAILS_ENV == 'production' || + process.env.VITE_LEGACY == 'enabled' + ); +}