Skip to content

Commit

Permalink
WIP: Rollup CJS Work (#5)
Browse files Browse the repository at this point in the history
* use rollup cjs fork

* reference merges branch

* add isMissing hook
  • Loading branch information
guybedford authored and rauchg committed Nov 13, 2018
1 parent 5508f37 commit 69af853
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 23 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
const rollup = require("rollup");
const resolve = require("rollup-plugin-node-resolve");
const nodeResolve = require("rollup-plugin-node-resolve");
const commonjs = require("rollup-plugin-commonjs");
const json = require("rollup-plugin-json");
const { terser } = require("rollup-plugin-terser");
const builtins = require("builtins")();

module.exports = async (input, { minify = true } = {}) => {
const resolve = nodeResolve({
module: false,
jsnext: false,
browser: false,
preferBuiltins: true,
});
const bundle = await rollup.rollup({
input,
plugins: [resolve(), commonjs(), json(), ...(minify ? [terser()] : null)],
plugins: [
resolve,
commonjs({
// simple optional dependencies detection
async isMissing (id, parentId) {
try {
if (builtins[id] || await resolve.resolveId(id, parentId))
return false;
}
catch {}
return true;
}
}),
json(),
...(minify ? [terser()] : null)
],
external: builtins
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"arg": "^2.0.0",
"builtins": "^2.0.0",
"rollup": "0.67.1",
"rollup-plugin-commonjs": "9.2.0",
"rollup-plugin-commonjs": "git+ssh://[email protected]/zeit/rollup-plugin-commonjs#merges",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "3.4.0",
"rollup-plugin-terser": "^3.0.0"
Expand Down

0 comments on commit 69af853

Please sign in to comment.