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

Completely remove tree-shaken dynamic imports from bundle information #2663

Merged
merged 2 commits into from Jan 21, 2019
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
2 changes: 1 addition & 1 deletion src/Chunk.ts
Expand Up @@ -169,7 +169,7 @@ export default class Chunk {
}

getDynamicImportIds(): string[] {
return this.dynamicDependencies.map(chunk => chunk.id);
return this.dynamicDependencies.map(chunk => chunk.id).filter(Boolean);
}

getExportNames(): string[] {
Expand Down
40 changes: 40 additions & 0 deletions test/misc/bundle-information.js
Expand Up @@ -265,6 +265,46 @@ describe('The bundle object', () => {
});
});

it('removes tree-shaken dynamic imports', () => {
return rollup
.rollup({
input: ['input'],
plugins: [
loader({
input: `export default false ? import('dynamic') : null`,
dynamic: `export default 'dynamic'`
})
]
})
.then(bundle =>
bundle.generate({
format: 'esm',
dir: 'dist',
entryFileNames: '[name].js',
chunkFileNames: 'generated-[name].js'
})
)
.then(({ output }) => {
assert.deepEqual(output.map(chunk => chunk.fileName), ['input.js'], 'fileName');
assert.deepEqual(output.map(chunk => chunk.imports), [[]], 'imports');
assert.deepEqual(output.map(chunk => chunk.dynamicImports), [[]], 'dynamicImports');
assert.deepEqual(
output.map(chunk => chunk.modules),
[
{
input: {
originalLength: 47,
removedExports: [],
renderedExports: ['default'],
renderedLength: 17
}
}
],
'modules'
);
});
});

it('adds correct flags to files when preserving modules', () => {
return rollup
.rollup({
Expand Down