Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
npm install --save-dev rollup-plugin-commonjs
Typically, you would use this plugin alongside rollup-plugin-node-resolve, so that you could bundle your CommonJS dependencies in
// rollup.config.js;;entry: 'main.js'dest: 'bundle.js'format: 'iife'plugins:;
This plugin will attempt to create named exports, where appropriate, so you can do this...
// importer.js;// exporter.jsmoduleexports = named: 42 ; // or `exports.named = 42;`
...but that's not always possible:
// importer.js;// my-lib.jsvar myLib = exports;myLibnamed = 'you can\'t see me';
In those cases, you can specify custom named exports:
ES modules are always parsed in strict mode. That means that certain non-strict constructs (like octal literals) will be treated as syntax errors when Rollup parses modules that use them. Some older CommonJS modules depend on those constructs, and if you depend on them your bundle will blow up. There's basically nothing we can do about that.
Luckily, there is absolutely no good reason not to use strict mode for everything — so the solution to this problem is to lobby the authors of those modules to update them.