Home

Awesome

rollup-plugin-purs

Bundles PureScript modules with Rollup

Why Rollup?

Here are the file sizes for the examples/tab-organizer program:

BundlerUnminifiedJSMinUglifyJS
rollup-plugin-purs112.2 kB70.3 kB35.7 kB
purs bundle157.8 kB107.2 kB65.2 kB
webpack977.4 kB654.0 kB178.8 kB

Installation

  1. Add the following to your package.json:

    "devDependencies": {
      "rollup": "^0.41.6",
      "rollup-plugin-purs": "^1.0.35"
    },
    "scripts": {
      "build": "rollup --config"
    }
    
  2. Run npm install

  3. Place this code into a file called rollup.config.js:

    import purs from "rollup-plugin-purs";
    
    export default {
      entry: "src/Main.purs",
      dest: "bundle.js",
      format: "iife",
      sourceMap: true,
      plugins: [
        purs()
      ]
    };
    
  4. This plugin does not compile PureScript code, so you will need to run pulp build -- --source-maps (or equivalent)

  5. Run npm run build

  6. The final bundle is in the bundle.js file. Enjoy the smaller file size and optimizations!

You can see an example program in the examples/pulp init folder.

Options

These are the default options:

purs({
  include: undefined,      // Glob pattern for files/directories to include
  exclude: undefined,      // Glob pattern for files/directories to exclude
  buildDir: "output",      // Directory where the `purs compile` files are located
  runMain: true,           // Whether to call the `main` function or not
  debug: true,             // Displays additional warnings and statistics
  optimizations: {
    uncurry: true,         // Whether to apply the uncurrying optimization or not
    inline: true,          // Whether to inline some functions or not
    removeDeadCode: true,  // Whether to remove dead code or not
    assumePureVars: true   // Whether to assume that variable assignment is always pure
  }
})

The default options should be fine for most use cases.

Optimizations

These are the optimizations which can be turned on or off:

In addition to the above optimizations, there are some optimizations which are always applied:

Planned optimizations

Comment pragmas

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.

Converting from CommonJS to ES6 modules

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).

License

MIT