Skip to content

Commit

Permalink
refactor(legacy): build polyfill chunk (#9639)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Aug 19, 2022
1 parent bc4a627 commit 7ba0c9f
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,6 @@ async function buildPolyfillChunk(
plugins: [polyfillsPlugin(imports, excludeSystemJS)],
build: {
write: false,
// if a value above 'es5' is set, esbuild injects helper functions which uses es2015 features
target: 'es5',
minify,
assetsDir,
rollupOptions: {
Expand All @@ -646,6 +644,18 @@ async function buildPolyfillChunk(
entryFileNames: rollupOutputOptions.entryFileNames
}
}
},
// Don't run esbuild for transpilation or minification
// because we don't want to transpile code.
esbuild: false,
optimizeDeps: {
esbuildOptions: {
// If a value above 'es5' is set, esbuild injects helper functions which uses es2015 features.
// This limits the input code not to include es2015+ codes.
// But core-js is the only dependency which includes commonjs code
// and core-js doesn't include es2015+ codes.
target: 'es5'
}
}
})
const _polyfillChunk = Array.isArray(res) ? res[0] : res
Expand Down Expand Up @@ -685,21 +695,6 @@ function polyfillsPlugin(
(excludeSystemJS ? '' : `import "systemjs/dist/s.min.js";`)
)
}
},
renderChunk(_, __, opts) {
// systemjs includes code that can't be minified down to es5 by esbuild
if (!excludeSystemJS) {
// @ts-ignore avoid esbuild transform on legacy chunks since it produces
// legacy-unsafe code - e.g. rewriting object properties into shorthands
opts.__vite_skip_esbuild__ = true

// @ts-ignore force terser for legacy chunks. This only takes effect if
// minification isn't disabled, because that leaves out the terser plugin
// entirely.
opts.__vite_force_terser__ = true
}

return null
}
}
}
Expand Down

0 comments on commit 7ba0c9f

Please sign in to comment.