From 66610391c602170941e3771b85238f68817b1000 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 30 Jun 2022 17:10:50 +0200 Subject: [PATCH] Revert "fix(import): present in vite-legacy" This reverts commit 65f3f64545eaee9b9e29a610b7548cfd022f015a. --- Gemfile | 1 + Gemfile.lock | 3 +++ vite.config.ts | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index a26e635c271..9a2e93fc262 100644 --- a/Gemfile +++ b/Gemfile @@ -86,6 +86,7 @@ gem 'strong_migrations' # lint database migrations gem 'turbo-rails' gem 'typhoeus' gem 'view_component' +gem 'vite_plugin_legacy' gem 'vite_rails' gem 'warden' gem 'zipline' diff --git a/Gemfile.lock b/Gemfile.lock index f4c90b485cc..76aca1a31f6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -749,6 +749,8 @@ GEM axiom-types (~> 0.1) coercible (~> 1.0) descendants_tracker (~> 0.0, >= 0.0.3) + vite_plugin_legacy (3.0.2) + vite_ruby (~> 3.0, >= 3.0.4) vite_rails (3.0.9) railties (>= 5.1, < 8) vite_ruby (~> 3.0) @@ -910,6 +912,7 @@ DEPENDENCIES typhoeus vcr view_component + vite_plugin_legacy vite_rails warden web-console diff --git a/vite.config.ts b/vite.config.ts index 03f4b410cd8..da4c34eda64 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,5 +1,6 @@ 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'; @@ -12,10 +13,49 @@ const plugins = [ FullReload(['config/routes.rb', 'app/views/**/*'], { delay: 200 }) ]; +if (shouldBuildLegacy()) { + plugins.push( + 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' + ] + }) + ); +} + export default defineConfig({ resolve: { alias: { '@utils': '/shared/utils.ts' } }, build: { - sourcemap: true + sourcemap: true, + polyfillDynamicImport: true }, plugins }); + +function shouldBuildLegacy() { + if (process.env.VITE_LEGACY == 'disabled') { + return false; + } + return ( + process.env.RAILS_ENV == 'production' || + process.env.VITE_LEGACY == 'enabled' + ); +}