• In order to use Espruino modules (and other CommonJS modules) a few extra steps are required, especially if you also want to uglify/minify the code. This assumes you already have Node, npm and Rollup installed.

    First, install the plugins…

    npm install rollup-plugin-espruino
    npm install rollup-plugin-commonjs
    npm install rollup-plugin-uglify
    

    You need to use the "harmony" branch of the uglify-js library for the uglify plugin to support ES modules. This will fetch it from GitHub:

    npm install mishoo/UglifyJS2#harmony
    

    Finally, add the following configuration to your Rollup config (rollup.config.js if using the CLI):

    import espruino from 'rollup-plugin-espruino'
    import commonjs from 'rollup-plugin-commonjs'
    import uglify from 'rollup-plugin-uglify'
    import { minify } from 'uglify-js'
    
    export default {
      entry: 'src/main.js',
      dest: 'dist/bundle.js',
      format: 'es',
      plugins: [
        commonjs(),
        uglify({}, minify),
        espruino(),
      ],
    }
    

    Here I'm passing the "harmony" branch of uglify-js as minify to the uglify plugin.

    And with that, it should work as expected. In harmony.

    Luckily, other plugins are more straight forward.

About

Avatar for Joakim @Joakim started