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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default exports not working on CJS + treeshake: true #815

Merged
merged 2 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/plugins/tree-shaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const treeShakingPlugin = ({
})

const result = await bundle.generate({
interop: 'auto',
format: this.format,
file: 'out.js',
sourcemap: !!this.options.sourcemap,
Expand Down
49 changes: 49 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,55 @@ test('use rollup for treeshaking', async () => {
)
})

test('use rollup for treeshaking --format cjs', async () => {
const { getFileContent } = await run(
getTestName(),
{
'package.json': `{
"dependencies": {
"react-select": "5.7.0",
"react": "17.0.2",
"react-dom": "17.0.2"
}
}`,
'input.tsx': `
import ReactSelect from 'react-select'

export const Component = (props: {}) => {
return <ReactSelect {...props} />
};
`,
'tsconfig.json': `{
"compilerOptions": {
"baseUrl": ".",
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"rootDir": ".",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es6",
"importHelpers": true,
"outDir": "dist"
}
}`,
},
{
entry: ['input.tsx'],
flags: ['--treeshake', '--target', 'es2022', '--format', 'cjs'],
}
)

expect(await getFileContent('dist/input.js')).toContain(
`jsxRuntime.jsx(ReactSelect__default.default`
)
})

test('custom output extension', async () => {
const { outFiles } = await run(
getTestName(),
Expand Down
5 changes: 5 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
"private": true,
"devDependencies": {
"@egoist/path-parser": "1.0.4",
"@types/react": "17.0.50",
"@types/react-dom": "17.0.17",
"graphql": "^15.3.0",
"graphql-tools": "^5.0.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-select": "5.7.0",
"vue": "3.2.36",
"vue-router": "4.0.15"
},
Expand Down