Skip to content

Commit

Permalink
Do not include tree-shaken dynamic imports in bundle information (#2663)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 21, 2019
1 parent a7eb784 commit 296035e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
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

0 comments on commit 296035e

Please sign in to comment.