Skip to content

Commit 44bfe2d

Browse files
committed
added Rollup Analyzer for bundle analysis
caveats: * analyzer options (limit, filter) should be configurable - but where? * ideally, low-level modules like `lib/bundle/bundler.js` shouldn't be responsible for printing user-facing messages (in this case, I didn't want to pass through `bundle` - but perhaps there's a more elegant way after all?) * `configDir` needs to be passed through for use as `root` (cf. inline comment; I just haven't gotten around to doing that yet) as suggested by @moonglum
1 parent 0d27b59 commit 44bfe2d

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

lib/bundle/bundler.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
let rollup = require("rollup");
2+
let rollupAnalyzer = require("rollup-analyzer");
3+
4+
let report = msg => void console.error(msg);
25

36
module.exports = function generateBundle(entryPoint, target, config, cache) {
47
let { readConfig, writeConfig } = config;
58
let options = Object.assign({}, readConfig, {
69
input: entryPoint,
710
cache
811
});
12+
let analyzer = rollupAnalyzer({ // TODO: configurable
13+
//root // TODO: pass through `configDir`
14+
limit: 5
15+
});
916
return rollup.rollup(options).
17+
then(bundle => {
18+
return analyzer.formatted(bundle).
19+
then(report, report).
20+
then(_ => bundle);
21+
}).
1022
then(bundle => {
1123
let modules = bundle.modules.reduce(collectModulePaths, new Set());
1224
return bundle.generate(writeConfig).

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = (config, assetManager, { watcher, browsers, compact } = {}) =>
2222
watcher.on("edit", filepaths => {
2323
bundles.forEach(bundle => {
2424
let res = bundle.recompile(...filepaths);
25-
res && // guards against irrelevant changes
25+
res && // disregard irrelevant changes
2626
res.then(makeWriter(bundle, assetManager));
2727
});
2828
});

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"faucet-pipeline": "~1.0.0-rc.3",
3030
"rollup": "^0.56.5",
3131
"rollup-plugin-cleanup": "^2.0.0",
32-
"rollup-plugin-commonjs": "^9.0.0",
32+
"rollup-plugin-commonjs": "^9.1.0",
3333
"rollup-plugin-node-resolve": "^3.2.0"
3434
},
3535
"devDependencies": {
@@ -38,8 +38,9 @@
3838
"faucet-pipeline-jsx": "file:pkg/faucet-pipeline-jsx",
3939
"faucet-pipeline-typescript": "file:pkg/faucet-pipeline-typescript",
4040
"json-diff": "^0.5.2",
41-
"mocha": "^5.0.3",
41+
"mocha": "^5.0.4",
4242
"npm-run-all": "^4.1.2",
43-
"release-util-fnd": "^1.1.0"
43+
"release-util-fnd": "^1.1.0",
44+
"rollup-analyzer": "^1.1.0"
4445
}
4546
}

0 commit comments

Comments
 (0)