npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-purs

v1.0.38

Published

Bundle PureScript modules with Rollup

Downloads

347

Readme

rollup-plugin-purs

Bundles PureScript modules with Rollup

Why Rollup?

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

| Bundler | Unminified | JSMin | UglifyJS | | ------------------ | ---------: | ---------: | ---------: | | rollup-plugin-purs | 112.2 kB | 70.3 kB | 35.7 kB | | purs bundle | 157.8 kB | 107.2 kB | 65.2 kB | | webpack | 977.4 kB | 654.0 kB | 178.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:

  • uncurry

    Replaces curried functions with uncurried functions, for improved performance and smaller file size.

  • inline

    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.

  • removeDeadCode

    Removes code which is not used. This dramatically reduces the file size.

  • assumePureVars

    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.

    If assumePureVars is false, then rollup-plugin-purs only 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.

    If assumePureVars is true, then rollup-plugin-purs will remove all unused variables, even if it can't prove that the variables are pure.

    PureScript variables are always pure, so assumePureVars is safe. But if you do weird things with the FFI, or if you use an unsafe PureScript function, or if you import a JavaScript library, then assumePureVars might break your program.

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

  • Constant propagation / folding

Planned optimizations

  • Common subexpression elimination

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