File tree Expand file tree Collapse file tree 4 files changed +71
-2
lines changed
Expand file tree Collapse file tree 4 files changed +71
-2
lines changed Original file line number Diff line number Diff line change 145145 "sirv" : " ^3.0.0" ,
146146 "source-map-support" : " ^0.5.21" ,
147147 "strip-literal" : " ^2.1.1" ,
148+ "terser" : " ^5.37.0" ,
148149 "tinyglobby" : " ^0.2.10" ,
149150 "tsconfck" : " ^3.1.4" ,
150151 "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 11import type { Terser } from 'dep-types/terser'
2- import { Worker } from 'artichokie'
2+ import { WorkerWithFallback } from 'artichokie'
33import type { Plugin } from '../plugin'
44import type { ResolvedConfig } from '..'
55import { requireResolveFromRootWithFallback } from '../utils'
@@ -37,7 +37,7 @@ export function terserPlugin(config: ResolvedConfig): Plugin {
3737 const { maxWorkers, ...terserOptions } = config . build . terserOptions
3838
3939 const makeWorker = ( ) =>
40- new Worker (
40+ new WorkerWithFallback (
4141 ( ) =>
4242 async (
4343 terserPath : string ,
@@ -50,6 +50,16 @@ export function terserPlugin(config: ResolvedConfig): Plugin {
5050 return terser . minify ( code , options ) as Terser . MinifyOutput
5151 } ,
5252 {
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+ } ,
5363 max : maxWorkers ,
5464 } ,
5565 )
You can’t perform that action at this time.
0 commit comments