Skip to content

Instantly share code, notes, and snippets.

@tivac

tivac/README.md Secret

Last active January 16, 2019 21:38
Show Gist options
  • Save tivac/7ad94d821922b2009cca7d704e470d0e to your computer and use it in GitHub Desktop.
Save tivac/7ad94d821922b2009cca7d704e470d0e to your computer and use it in GitHub Desktop.
Rollup dynamic imports + tree-shaking API issue

Rollup bundle-splitting + tree-shaking bug

Install

  1. Click "Download zip" and extract to a folder
  2. cd into the extracted folder
  3. npm install
  4. npm start

The custom plugin in rollup.config.js will show an undefined value in the bundle argument passed to the generateBundle hook.

export default false
? import('./b.js')
: null;
export default "b";

Output

Actual

./a.js → ./dist...
{ entry: 'a.js', dynamicImports: [ undefined ] }
created ./dist in 21ms

Expected

./a.js → ./dist...
{ entry: 'a.js', dynamicImports: [ ] }
created ./dist in 20ms

Diff

./a.js → ./dist...
-{ entry: 'a.js', dynamicImports: [ ] }
+{ entry: 'a.js', dynamicImports: [ undefined ] }
created ./dist in 21ms
{
"name": "rollup-code-splitting-treeshaking-bug",
"version": "1.0.0",
"description": "Repro for a rollup bug",
"scripts": {
"start": "rollup --config"
},
"license": "MIT",
"devDependencies": {
"rollup": "^1.1.0"
}
}
module.exports = {
input : [
"./a.js",
],
output : {
dir : "./dist",
format : "esm",
},
plugins : [
{
name : "rollup-code-splitting-treeshaking-bug",
generateBundle(options, bundle) {
Object.entries(bundle).forEach(([ entry, { dynamicImports }]) => {
console.log({ entry, dynamicImports });
});
},
},
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment