File tree 4 files changed +71
-2
lines changed
4 files changed +71
-2
lines changed Original file line number Diff line number Diff line change 145
145
"sirv" : " ^3.0.0" ,
146
146
"source-map-support" : " ^0.5.21" ,
147
147
"strip-literal" : " ^2.1.1" ,
148
+ "terser" : " ^5.37.0" ,
148
149
"tinyglobby" : " ^0.2.10" ,
149
150
"tsconfck" : " ^3.1.4" ,
150
151
"tslib" : " ^2.8.1" ,
Original file line number Diff line number Diff line change
1
+ import { resolve } from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { describe , expect , test } from 'vitest'
4
+ import { build } from 'vite'
5
+ import type { RollupOutput } from 'rollup'
6
+ import type { TerserOptions } from '../../plugins/terser'
7
+
8
+ const __dirname = resolve ( fileURLToPath ( import . meta. url ) , '..' )
9
+
10
+ describe ( 'terser' , ( ) => {
11
+ const run = async ( terserOptions : TerserOptions ) => {
12
+ const result = ( await build ( {
13
+ root : resolve ( __dirname , '../packages/build-project' ) ,
14
+ logLevel : 'silent' ,
15
+ build : {
16
+ write : false ,
17
+ minify : 'terser' ,
18
+ terserOptions,
19
+ } ,
20
+ plugins : [
21
+ {
22
+ name : 'test' ,
23
+ resolveId ( id ) {
24
+ if ( id === 'entry.js' ) {
25
+ return '\0' + id
26
+ }
27
+ } ,
28
+ load ( id ) {
29
+ if ( id === '\0entry.js' ) {
30
+ return `const foo = 1;console.log(foo)`
31
+ }
32
+ } ,
33
+ } ,
34
+ ] ,
35
+ } ) ) as RollupOutput
36
+ return result . output [ 0 ] . code
37
+ }
38
+
39
+ test ( 'basic' , async ( ) => {
40
+ await run ( { } )
41
+ } )
42
+
43
+ test ( 'nth' , async ( ) => {
44
+ const resultCode = await run ( {
45
+ mangle : {
46
+ nth_identifier : {
47
+ get : ( n ) => {
48
+ return 'prefix_' + n . toString ( )
49
+ } ,
50
+ } ,
51
+ } ,
52
+ } )
53
+ expect ( resultCode ) . toContain ( 'prefix_' )
54
+ } )
55
+ } )
Original file line number Diff line number Diff line change 1
1
import type { Terser } from 'dep-types/terser'
2
- import { Worker } from 'artichokie'
2
+ import { WorkerWithFallback } from 'artichokie'
3
3
import type { Plugin } from '../plugin'
4
4
import type { ResolvedConfig } from '..'
5
5
import { requireResolveFromRootWithFallback } from '../utils'
@@ -37,7 +37,7 @@ export function terserPlugin(config: ResolvedConfig): Plugin {
37
37
const { maxWorkers, ...terserOptions } = config . build . terserOptions
38
38
39
39
const makeWorker = ( ) =>
40
- new Worker (
40
+ new WorkerWithFallback (
41
41
( ) =>
42
42
async (
43
43
terserPath : string ,
@@ -50,6 +50,16 @@ export function terserPlugin(config: ResolvedConfig): Plugin {
50
50
return terser . minify ( code , options ) as Terser . MinifyOutput
51
51
} ,
52
52
{
53
+ shouldUseFake ( _terserPath , _code , options ) {
54
+ return ! ! (
55
+ ( typeof options . mangle === 'object' &&
56
+ ( options . mangle . nth_identifier ?. get ||
57
+ ( typeof options . mangle . properties === 'object' &&
58
+ options . mangle . properties . nth_identifier ?. get ) ) ) ||
59
+ typeof options . format ?. comments === 'function' ||
60
+ typeof options . output ?. comments === 'function'
61
+ )
62
+ } ,
53
63
max : maxWorkers ,
54
64
} ,
55
65
)
You can’t perform that action at this time.
0 commit comments