diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1fc46b11..27938598 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -86,26 +86,26 @@ devDependencies: packages: - /@babel/code-frame/7.16.7: - resolution: {integrity: sha512-iAXqUn8IIeBTNd72xsFlgaXHkMBMt6y4HJp1tIaK465CWLT/fG1aqB7ykr95gHHmlBdGbFeWWfyB4NJJ0nmeIg==} + /@babel/code-frame/7.18.6: + resolution: {integrity: sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q==} engines: {node: '>=6.9.0'} requiresBuild: true dependencies: - '@babel/highlight': 7.16.10 + '@babel/highlight': 7.18.6 dev: true optional: true - /@babel/helper-validator-identifier/7.16.7: - resolution: {integrity: sha512-hsEnFemeiW4D08A5gUAZxLBTXpZ39P+a+DGDsHw1yxqyQ/jzFEnxf5uTEGp+3bzAbNOxU1paTgYS4ECU/IgfDw==} + /@babel/helper-validator-identifier/7.18.6: + resolution: {integrity: sha512-MmetCkz9ej86nJQV+sFCxoGGrUbU3q02kgLciwkrt9QqEB7cP39oKEY0PakknEO0Gu20SskMRi+AYZ3b1TpN9g==} engines: {node: '>=6.9.0'} dev: true optional: true - /@babel/highlight/7.16.10: - resolution: {integrity: sha512-5FnTQLSLswEj6IkgVw5KusNUUFY9ZGqe/TRFnP/BKYHYgfh7tc+C7mwiy95/yNP7Dh9x580Vv8r7u7ZfTBFxdw==} + /@babel/highlight/7.18.6: + resolution: {integrity: sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==} engines: {node: '>=6.9.0'} dependencies: - '@babel/helper-validator-identifier': 7.16.7 + '@babel/helper-validator-identifier': 7.18.6 chalk: 2.4.2 js-tokens: 4.0.0 dev: true @@ -209,6 +209,7 @@ packages: engines: {node: '>=10'} cpu: [arm64] os: [linux] + libc: [glibc] requiresBuild: true dev: true optional: true @@ -218,6 +219,7 @@ packages: engines: {node: '>=10'} cpu: [arm64] os: [linux] + libc: [musl] requiresBuild: true dev: true optional: true @@ -227,6 +229,7 @@ packages: engines: {node: '>=10'} cpu: [x64] os: [linux] + libc: [glibc] requiresBuild: true dev: true optional: true @@ -236,6 +239,7 @@ packages: engines: {node: '>=10'} cpu: [x64] os: [linux] + libc: [musl] requiresBuild: true dev: true optional: true @@ -1600,7 +1604,7 @@ packages: rollup: 2.74.1 typescript: 4.6.3 optionalDependencies: - '@babel/code-frame': 7.16.7 + '@babel/code-frame': 7.18.6 dev: true /rollup-plugin-hashbang/2.2.2: diff --git a/src/plugins/es5.ts b/src/plugins/es5.ts index a689b741..5d1030c7 100644 --- a/src/plugins/es5.ts +++ b/src/plugins/es5.ts @@ -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 { diff --git a/test/index.test.ts b/test/index.test.ts index 63b67dab..3676025d 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -443,7 +443,6 @@ test('svelte: typescript support', async () => { expect(output).toContain('// Component.svelte') }) - test('onSuccess', async () => { const { logs } = await run( getTestName(), @@ -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') @@ -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) @@ -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(),