Skip to content

Commit 34df1da

Browse files
Nikapleegoist
andauthored
feat: improve minification for --target es5 (#664)
* feat: improve minification for `--target es5` * remove .only Co-authored-by: EGOIST <0x142857@gmail.com>
1 parent 407cec6 commit 34df1da

File tree

3 files changed

+56
-18
lines changed

3 files changed

+56
-18
lines changed

pnpm-lock.yaml

Lines changed: 13 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/es5.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ export const es5 = (): Plugin => {
3535
parser: {
3636
syntax: 'ecmascript',
3737
},
38+
minify: this.options.minify ? {
39+
compress: false,
40+
mangle: {
41+
reserved: this.options.globalName ? [this.options.globalName] : []
42+
},
43+
} : undefined,
3844
},
3945
})
4046
return {

test/index.test.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ test('svelte: typescript support', async () => {
443443
expect(output).toContain('// Component.svelte')
444444
})
445445

446-
447446
test('onSuccess', async () => {
448447
const { logs } = await run(
449448
getTestName(),
@@ -460,11 +459,9 @@ test('onSuccess', async () => {
460459
})
461460

462461
test('onSuccess: use a function from config file', async () => {
463-
const { logs } = await run(
464-
getTestName(),
465-
{
466-
'input.ts': "console.log('test');",
467-
'tsup.config.ts': `
462+
const { logs } = await run(getTestName(), {
463+
'input.ts': "console.log('test');",
464+
'tsup.config.ts': `
468465
export default {
469466
onSuccess: async () => {
470467
console.log('hello')
@@ -475,9 +472,8 @@ test('onSuccess: use a function from config file', async () => {
475472
}, 1_000)
476473
})
477474
}
478-
}`
479-
},
480-
)
475+
}`,
476+
})
481477

482478
expect(logs.includes('hello')).toEqual(true)
483479
expect(logs.includes('world')).toEqual(true)
@@ -824,6 +820,38 @@ test('es5 target', async () => {
824820
expect(outFiles).toEqual(['input.js'])
825821
})
826822

823+
test('es5 minify', async () => {
824+
const { getFileContent, outFiles } = await run(
825+
getTestName(),
826+
{
827+
'input.ts': `
828+
export class Foo {
829+
hi (): void {
830+
let a = () => 'foo'
831+
832+
console.log(a())
833+
}
834+
}
835+
`,
836+
},
837+
{
838+
flags: [
839+
'--target',
840+
'es5',
841+
'--format',
842+
'iife',
843+
'--globalName',
844+
'FooAPI',
845+
'--minify',
846+
],
847+
}
848+
)
849+
expect(outFiles).toEqual(['input.global.js'])
850+
const iifeBundle = await getFileContent('dist/input.global.js')
851+
expect(iifeBundle).toMatch(/var FooAPI/)
852+
expect(iifeBundle).not.toMatch(/createClass/)
853+
})
854+
827855
test('multiple targets', async () => {
828856
const { output, outFiles } = await run(
829857
getTestName(),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy