Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@vitejs/plugin-legacy] Bundles polyfills-modern even when renderLegacyChunks is false #3695

Closed
DreierF opened this issue Jun 7, 2021 · 1 comment

Comments

@DreierF
Copy link
Contributor

DreierF commented Jun 7, 2021

Describe the bug

Since version 1.4.0 the @vitejs/plugin-legacy automatically tries to restore the previous behavior of polyfilling dynamic import.
However this currently ignores the value of renderLegacyChunks. When it is set to false only additional polyfills for modern browsers are applied. In this case the plugin should not overwrite the value set via build.polyfillDynamicImport = false and therefore only bundle dynamic import polyfills when the user explicitly set build.polyfillDynamicImport = true.

Cause:

config.build.polyfillDynamicImport = true

Reproduction

export default defineConfig({
	build: {
		target: 'es2017',
		polyfillDynamicImport: false,
		// ...
	},
	plugins: [
		// ...
		legacy({
			modernPolyfills: [
				'es.promise.finally',
				'es.array.flat',
				'es.array.flat-map',
			],
			renderLegacyChunks: false
		}),
		// ...
	],
});

Logs

As you can see in the logs below polyfillDynamicImport is always set to true.

  vite:config bundled config file loaded in 175ms +0ms
  vite:config using resolved config: {
  vite:config   base: './',
  vite:config   optimizeDeps: {
  vite:config     exclude: [ 'ts-closure-library/lib/ui/tree' ],
  vite:config     esbuildOptions: { keepNames: undefined }
  vite:config   },
  vite:config   resolve: {
  vite:config     dedupe: undefined,
  vite:config     alias: [
  vite:config       [Object], [Object],
  vite:config       [Object], [Object],
  vite:config       [Object], [Object],
  vite:config       [Object]
  vite:config     ]
  vite:config   },
  vite:config   build: {
  vite:config     target: 'es2017',
  vite:config     polyfillDynamicImport: true,
  vite:config     outDir: 'build/vite/META-INF/web',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: true,
  vite:config     rollupOptions: { external: [Array] },
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     minify: 'terser',
  vite:config     terserOptions: {},
  vite:config     cleanCssOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     brotliSize: false,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null
  vite:config   },
  vite:config   plugins: [
  vite:config     'alias',
  vite:config     'react-refresh',
  vite:config     'vite:tsconfig-paths',
  vite:config     'vite:dynamic-import-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'legacy-config',
  vite:config     'legacy-generate-polyfill-chunk',
  vite:config     'legacy-env',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'rollup-plugin-dynamic-import-variables',
  vite:config     'legacy-post-process',
  vite:config     'vite:import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter'
  vite:config   ],
  vite:config   server: {
  vite:config     host: '127.0.0.1',
  vite:config     port: 9090,
  vite:config     strictPort: true,
  vite:config     watch: { ignored: [Array] },
  vite:config     fsServe: {
  vite:config       root: '...',
  vite:config       strict: false
  vite:config     }
  vite:config   },
  vite:config   css: {
  vite:config     preprocessorOptions: { less: [Object] },
  vite:config     modules: { localsConvention: 'camelCase' }
  vite:config   },
  vite:config   define: { 'import.meta.env.LEGACY': '__VITE_IS_LEGACY__' },
  vite:config   configFile: '/Users/florian/Documents/CQSE/TeamscaleWebpack/engine/com.teamscale.ui/vite.config.ts',
  vite:config   configFileDependencies: [ 'vite.config.ts' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     build: {}
  vite:config   },
  vite:config   root: '/Users/florian/Documents/CQSE/TeamscaleWebpack/engine/com.teamscale.ui',
  vite:config   publicDir: '/Users/florian/Documents/CQSE/TeamscaleWebpack/engine/com.teamscale.ui/public',
  vite:config   cacheDir: '/Users/florian/Documents/CQSE/TeamscaleWebpack/engine/com.teamscale.ui/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isProduction: true,
  vite:config   env: { BASE_URL: './', MODE: 'production', DEV: false, PROD: true },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen]
  vite:config   },
  vite:config   createResolver: [Function: createResolver]
  vite:config } +136ms
@DreierF
Copy link
Contributor Author

DreierF commented Sep 21, 2021

Fixed with #3774

@DreierF DreierF closed this as completed Sep 21, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants