Skip to content

Commit

Permalink
fix: disable minification if minify is false
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Feb 15, 2023
1 parent d67bdb3 commit c7bca76
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
env: createSwcEnvOptions(targets, {
needPolyfills,
}),
}
const transformResult = await swc.transform(raw, {
...swcOptions,
inputSourceMap: undefined, // sourceMaps ? chunk.map : undefined, `.map` TODO: moved to OutputChunk?
jsc: {
transform: {
optimizer: {
Expand All @@ -442,6 +446,18 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
},
},
},
},
})
const plugin = swc.plugins([
recordAndRemovePolyfillSwcPlugin(legacyPolyfills),
wrapIIFESwcPlugin(),
])
const ast = await swc.parse(transformResult.code)
const result = await swc.print(plugin(ast), {
...swcOptions,
inputSourceMap: transformResult.map,
minify: Boolean(resolvedConfig.build.minify),
jsc: {
minify: {
compress: {
// Different defaults between terser and swc
Expand All @@ -457,20 +473,6 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
toplevel: opts.format === 'cjs',
},
},
}
const transformResult = await swc.transform(raw, {
...swcOptions,
inputSourceMap: undefined, // sourceMaps ? chunk.map : undefined, `.map` TODO: moved to OutputChunk?
})
const plugin = swc.plugins([
recordAndRemovePolyfillSwcPlugin(legacyPolyfills),
wrapIIFESwcPlugin(),
])
const ast = await swc.parse(transformResult.code)
const result = await swc.print(plugin(ast), {
...swcOptions,
inputSourceMap: transformResult.map,
minify: Boolean(resolvedConfig.build.minify),
})

return result
Expand Down

0 comments on commit c7bca76

Please sign in to comment.