File tree Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -306,9 +306,7 @@ export function resolveBuildPlugins(config: ResolvedConfig): {
306
306
post : [
307
307
buildImportAnalysisPlugin ( config ) ,
308
308
buildEsbuildPlugin ( config ) ,
309
- ...( options . minify === 'terser'
310
- ? [ terserPlugin ( options . terserOptions ) ]
311
- : [ ] ) ,
309
+ ...( options . minify === 'terser' ? [ terserPlugin ( config ) ] : [ ] ) ,
312
310
...( options . manifest ? [ manifestPlugin ( config ) ] : [ ] ) ,
313
311
...( options . ssrManifest ? [ ssrManifestPlugin ( config ) ] : [ ] ) ,
314
312
buildReporterPlugin ( config ) ,
Original file line number Diff line number Diff line change @@ -215,7 +215,13 @@ export const buildEsbuildPlugin = (config: ResolvedConfig): Plugin => {
215
215
}
216
216
217
217
const target = config . build . target
218
- const minify = config . build . minify === 'esbuild'
218
+ const minify =
219
+ config . build . minify === 'esbuild' &&
220
+ // Do not minify ES lib output since that would remove pure annotations
221
+ // and break tree-shaking
222
+ // https://github.com/vuejs/vue-next/issues/2860#issuecomment-926882793
223
+ ! ( config . build . lib && opts . format === 'es' )
224
+
219
225
if ( ( ! target || target === 'esnext' ) && ! minify ) {
220
226
return null
221
227
}
Original file line number Diff line number Diff line change 1
1
import { Plugin } from '../plugin'
2
2
import { Worker } from 'okie'
3
3
import { Terser } from 'types/terser'
4
+ import { ResolvedConfig } from '..'
4
5
5
- export function terserPlugin ( options : Terser . MinifyOptions ) : Plugin {
6
+ export function terserPlugin ( config : ResolvedConfig ) : Plugin {
6
7
const worker = new Worker (
7
8
( basedir : string , code : string , options : Terser . MinifyOptions ) => {
8
9
// when vite is linked, the worker thread won't share the same resolve
@@ -20,9 +21,15 @@ export function terserPlugin(options: Terser.MinifyOptions): Plugin {
20
21
name : 'vite:terser' ,
21
22
22
23
async renderChunk ( code , _chunk , outputOptions ) {
24
+ // Do not minify ES lib output since that would remove pure annotations
25
+ // and break tree-shaking
26
+ if ( config . build . lib && outputOptions . format === 'es' ) {
27
+ return null
28
+ }
29
+
23
30
const res = await worker . run ( __dirname , code , {
24
31
safari10 : true ,
25
- ...options ,
32
+ ...config . build . terserOptions ,
26
33
sourceMap : ! ! outputOptions . sourcemap ,
27
34
module : outputOptions . format . startsWith ( 'es' ) ,
28
35
toplevel : outputOptions . format === 'cjs'
You can’t perform that action at this time.
0 commit comments