Skip to content

Commit

Permalink
feat: improve minification for --target es5 (#664)
Browse files Browse the repository at this point in the history
* feat: improve minification for `--target es5`

* remove .only

Co-authored-by: EGOIST <0x142857@gmail.com>
  • Loading branch information
Nikaple and egoist committed Jul 25, 2022
1 parent 407cec6 commit 34df1da
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
22 changes: 13 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/plugins/es5.ts
Expand Up @@ -35,6 +35,12 @@ export const es5 = (): Plugin => {
parser: {
syntax: 'ecmascript',
},
minify: this.options.minify ? {
compress: false,
mangle: {
reserved: this.options.globalName ? [this.options.globalName] : []
},
} : undefined,
},
})
return {
Expand Down
46 changes: 37 additions & 9 deletions test/index.test.ts
Expand Up @@ -443,7 +443,6 @@ test('svelte: typescript support', async () => {
expect(output).toContain('// Component.svelte')
})


test('onSuccess', async () => {
const { logs } = await run(
getTestName(),
Expand All @@ -460,11 +459,9 @@ test('onSuccess', async () => {
})

test('onSuccess: use a function from config file', async () => {
const { logs } = await run(
getTestName(),
{
'input.ts': "console.log('test');",
'tsup.config.ts': `
const { logs } = await run(getTestName(), {
'input.ts': "console.log('test');",
'tsup.config.ts': `
export default {
onSuccess: async () => {
console.log('hello')
Expand All @@ -475,9 +472,8 @@ test('onSuccess: use a function from config file', async () => {
}, 1_000)
})
}
}`
},
)
}`,
})

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

test('es5 minify', async () => {
const { getFileContent, outFiles } = await run(
getTestName(),
{
'input.ts': `
export class Foo {
hi (): void {
let a = () => 'foo'
console.log(a())
}
}
`,
},
{
flags: [
'--target',
'es5',
'--format',
'iife',
'--globalName',
'FooAPI',
'--minify',
],
}
)
expect(outFiles).toEqual(['input.global.js'])
const iifeBundle = await getFileContent('dist/input.global.js')
expect(iifeBundle).toMatch(/var FooAPI/)
expect(iifeBundle).not.toMatch(/createClass/)
})

test('multiple targets', async () => {
const { output, outFiles } = await run(
getTestName(),
Expand Down

1 comment on commit 34df1da

@vercel
Copy link

@vercel vercel bot commented on 34df1da Jul 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

tsup – ./

tsup-git-main-egoist.vercel.app
tsup-egoist.vercel.app
tsup.vercel.app
tsup.egoist.sh

Please sign in to comment.