Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: re-transpile excluded modules when target is es5 #1

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ function swc(options: PluginOptions = {}): Plugin {
},

renderChunk(code: string) {
if (options.jsc?.target === 'es5') {
// always do another swc transform to transpile
// unprocessed es2015/es6 node module files
return swcTransform(code, {
minify: Boolean(options.minify),
jsc: {
minify: options.jsc?.minify,
target: options.jsc?.target,
}
});
}
if (options.minify) {
return swcMinify(code, options.jsc?.minify);
}
Expand Down
28 changes: 28 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,34 @@ export { foo };
output[0].code.should.equal(`var foo = /*#__PURE__*/ custom("div", null, "foo");

export { foo };
`);
});

it('transpiles excluded modules when target is "es5"', async () => {
const dir = realFs(getTestName(), {
'./fixture/foo.js': `
const foo = 'foo';
export default foo;
`,
'./fixture/other.js': `
import foo from './foo'
console.log(foo)
export const bar = 'bar';
console.log(bar);
`,
});
const output = await build({
exclude: ['**/other.js'],
jsc: { target: 'es5' }
}, {
input: ['./fixture/other.js'],
dir
});
output[0].code.should.equal(`var foo = 'foo';
console.log(foo);
var bar = 'bar';
console.log(bar);
export { bar };
`);
});
});