calvinmetcalf / rollup-plugin-node-builtins

138 stars 40 forks source link

Add some docs for usage in conjunction with rollup-plugin-includepaths #41

Open sirugh opened 6 years ago

sirugh commented 6 years ago

The includepaths plugin has an external option that by default includes all of the node built-in modules.

I think you'll find that people using these two plugins together may run into problems because of this default behavior. For example, the below rollup plugin config will result in an erroneous bundle that doesn't include any necessary builtins used by whatever code is under src.

plugins: [
 includePaths: {
   paths: ['src']
 },
 globals(),
 builtins()
]
rollup v0.56.5
bundles src/entry.js → dist/bundle.js...
(!) Missing shims for Node.js built-ins
Creating a browser bundle that depends on 'url'. You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins
(!) Missing global variable name
Use output.globals to specify browser global variable names corresponding to external modules
~/code/temp/node_modules/rollup/dist/rollup.js (guessing 'url')
created dist/bundle.js in 613ms

Now, this functionality is documented in the includepaths plugin as I linked above, but it would definitely have saved me several hours if your plugin also included some reference to the scenario.

To fix this we had to simply add external: [] to the includePaths plugin options.

plugins: [
 includePaths: {
   paths: ['src'],
   external: []
 },
 globals(),
 builtins()
]

Let me know if you need me to expand on anything here.