Bundles PureScript modules with Rollup
Here are the file sizes for the
Add the following to your
Place this code into a file called
rollup.config.js:;entry: "src/Main.purs"dest: "bundle.js"format: "iife"sourceMap: trueplugins:;
This plugin does not compile PureScript code, so you will need to run
pulp build -- --source-maps(or equivalent)
npm run build
The final bundle is in the
bundle.jsfile. Enjoy the smaller file size and optimizations!
You can see an example program in the
examples/pulp init folder.
These are the default options:
The default options should be fine for most use cases.
These are the optimizations which can be turned on or off:
Replaces curried functions with uncurried functions, for improved performance and smaller file size.
Inlines some functions, which can increase performance and decrease the file size.
It also inlines typeclass instance methods when it can. This can dramatically improve performance and reduce the file size.
Removes code which is not used. This dramatically reduces the file size.
When there is a variable assignment like
var foo = ...it will assume that the
...is pure. When used in combination with
removeDeadCode, this significantly reduces the file size.
rollup-plugin-pursonly removes unused variables if it can prove that the variables are pure. But sometimes it won't remove unused variables, because it's not smart enough to realize that the variables are pure.
rollup-plugin-purswill remove all unused variables, even if it can't prove that the variables are pure.
PureScript variables are always pure, so
assumePureVarsmight break your program.
In addition to the above optimizations, there are some optimizations which are always applied:
- Constant propagation / folding
- Common subexpression elimination
You can disable certain warnings by including a special comment in your code:
// rollup-plugin-purs ignore dynamic exports
// rollup-plugin-purs ignore dynamic require
// rollup-plugin-purs ignore dynamic module
Each comment disables a specific warning.
The comments must be exactly the same as above, and they must be placed at the top-level of your code, with zero spaces to the left of the comment.
This package also contains a
convert-commonjs program which can be used to convert a file from CommonJS to ES6 modules.
You can run
node_modules/.bin/convert-commonjs input.js > output.js which will take the
input.js file (which is CommonJS) and will output to the
output.js file (which is ES6 modules).