After playing around with rollup, I think to get the dead code elimination from rollup is quite easy (need check with webpack too)
.hi.js
function test$1 (n){
return n + 1
}
function test$2(n){
return n + 3
}
export { test$1 as test, test$2 as test2}
.fib.js
import * as hi from './hi'
function test$1(n){
return hi.test(n) + 1;
}
function fib2 (n) {
return hi.test2(n) * 2 ;
}
var b = 2;
var c = 3;
var d = c + 2 ;
console.log(b);
export { test$1 as fib, fib2, d}
.app.js
import * as fib from './fib'
var x = fib.fib (fib.d)
console.log(x)
so I run the command rollup -f iife app.js
(function () {
'use strict';
function test$1$1 (n){
return n + 1
}
function test$1(n){
return test$1$1(n) + 1;
}
var b = 2;
var c = 3;
var d = c + 2;
console.log(b);
var x = test$1 (d);
console.log(x);
}());
the output looks good, rollup is smarter than I thought, it can handle * based import
webpack seems to do a horrible job..
webpack seems to do a horrible job..
Heh, yes it does, I have had, to be quite frank, horrible experiences with webpack, hence why I use brunch as my 'javascript build engine', but even that has been removed in my recent projects in exchange for just raw npm scripts usage (why need a build system when npm already 'is' one), so I've just been calling browserify (and recently rollup.js, it does the same as browserify, but better and faster, as you see). :-)
fixed in master
Just a note for anyone else who comes across this - to compile with ES6 modules you'll need to add the following key to bsconfig.json:
"package-specs": ["es6"],
After compiling, find the ES6 modules in lib/es6.
Even after doing this, a small app that builds a list, maps it, and outputs it is 25k.
@aaronshaf OCaml Lists need a lot of code from the standard library. If it's relevant, you can use arrays (with Js.Array.* functions) which don't require any overhead?
Also, using webpack with module concatenation and uglifyjs plugins with es6 modules does a very good job for dead code elimination (and even better with the define plugin for conditional compilation), I have basically 0 unused code with this.
Most helpful comment
Just a note for anyone else who comes across this - to compile with ES6 modules you'll need to add the following key to
bsconfig.json:After compiling, find the ES6 modules in
lib/es6.