Giter VIP home page Giter VIP logo

rollem's Introduction

rollem

Roll up multiple ES6 bundles at once

npm version Build status semantic-release js-standard-style

Deprecated

Rollup 0.42+ supports multiple configs per file exactly like rollem.

Why?

Rollup is great, but does not handle multiple bundles right out of the box. Rollem just handles a simple case

// rollem.config.js
module.exports = [{
  entry: 'src/foo.js',
  dest: 'dist/foo.js'
}, {
  entry: 'src/bar.js',
  dest: 'dist/bar.js'
}]

Which builds two bundles dist/foo.js and dist/bar.js when you run rollem.

Install and use

npm install -D rollem
// create rollem.config.js shown above
// then set script command
"build": "rollem"

You can pass --watch option in the command to enable simple bundle rebuild on changes.

You can pass -c <filename> to specify a different config file.

rollem.config.js

Almost the same syntax as rollup.config.js but exports an Array. You can use JavaScript module to create the list of configs dynamically.

// rollem.config.js with ES5
const configs = glob.sync('src/**/*-spec.js').map(toConfig)
module.exports = configs
// rollem.config.js with ES6
export default [{
  entry: 'src/foo.js',
  dest: 'dist/foo.js'
}, {
  entry: 'src/child-folder/bar.js',
  dest: 'dist/bar.js',
  format: 'umd',
  moduleName: 'bar',
  sourceMap: 'inline'
}]

API

In addition to the simple command line, you can use rollem via its module API. It exports a single function

const rollem = require('rollem')
rollem(configs, options)
  • configs - simple Array of Rollup config objects
  • options - object with options, right now only watch property is supported.

The rollem(configs, options) returns a Promise, resolved after the bundles have been built. The promise is resolved with the list of built files.

If you run rollem(configs, {watch: true}) then the resolved Promise will give you an event emitter. Every time there is a file change, you first will get "changed" event, and after the bundles have been built you will get an event "rolled".

rollem(configs, {watch: true})
  .then((ee) => {
    ee.on('changed', () => console.log('bundles will be rebuilt'))
    ee.on('rolled', () => console.log('new bundles have been built'))
  })

The rollem in watch mode tries to determine the folder to watch from the source files. Because it only knows about the top level entry file, it just grabs and watches the top parent folders. For example, if entries specify src/entry.js, src/foo/bar.js then the top parent folder watched will be src.

Debug

If something is wrong, run the tool with debug output enabled

DEBUG=rollem rollem

Small print

Author: Gleb Bahmutov <[email protected]> © 2016

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github

MIT License

Copyright (c) 2016 Gleb Bahmutov <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

rollem's People

Contributors

antifuchs avatar bahmutov avatar balloob avatar bfred-it avatar henrikjoreteg avatar just-boris avatar meszaros-lajos-gyorgy avatar nonameprovided avatar notetiene avatar snuggs avatar zemd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rollem's Issues

rollem --watch only builds sources after the first change (incompatibility with rollup --watch)

Hi!

Please take a look at the following files:

package.json

{
  "name": "issue",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "rollem": "rollem -c rollem.config.js",
    "rollemWatch": "npm run rollem -- --watch",
    "rollup": "rollup -c rollup.config.js",
    "rollupWatch": "npm run rollup -- -w"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "rollem": "^1.10.0",
    "rollup": "^0.41.4",
    "rollup-watch": "^3.2.2"
  }
}

rollup.config.js

export default {
  entry: 'src/index.js',
  dest: 'dist/script.js'
};

rollem.config.js

export default [{
  entry: 'src/index.js',
  dest: 'dist/script.js'
}];

Finally create an src folder with an index.js in it with any content.

If you run npm run rollupWatch, then the bundle gets built first and gets rebuilt after every change.
Opposed to this when you run npm run rollemWatch, there is no building of the bundle, it only gets built once you do any changes in the source file.

require in rollem.config.js doesn't work

When I am trying to import relative module, like it doesn't work. For example, the following rollem.config.js fails

import helper from './my-helper';

export default [/* ...entries... */]

Gives me an error Error: Cannot find module './my-helper.js'

It happens because you are using eval that uses require from the current module context, but not the original rollem.config.js location.

See how that was worked around in Rollup. I think that this trick with temporary replaced require hook should be ported there as well.

rollem+rollup-plugin-multi-entry cause error

I made rollem.config.js:

import typescript from 'rollup-plugin-typescript';
import multiEntry from 'rollup-plugin-multi-entry';

export default [{
  entry: './src/scripts/Main.ts',
  dest: './dist/index.js',
  format: 'iife',
  plugins: [typescript()]
}, {
  entry: 'test/**/*.ts',
  dest: './dist/test.js',
  format: 'es',
  plugins: [
    multiEntry(),
    typescript()
  ]
}];

and executed this command:
rollem -c rollem.config.js --watch

then I received:

Treating 'rollup-plugin-typescript' as external dependency
Treating 'rollup-plugin-node-resolve' as external dependency
Treating 'rollup-plugin-commonjs' as external dependency
Treating 'rollup-plugin-json' as external dependency
Treating 'rollup-plugin-multi-entry' as external dependency
[06:30:31 GMT+0000 (UTC)] watching source folders for changes [ 'src/scripts', 'test/**' ]
/home/ubuntu/workspace/node_modules/watch/main.js:73
    if (err) throw err;
             ^

Error: ENOENT: no such file or directory, stat 'test/**'

Please check this issue.
Thanks.

Allow returning a stream

I've made some experiments with rollup-stream and rollem to try to glue them together and it seems it would be much easier if we simply added an option like options.stream. Instead of simply returning a list of destination, it could be a stream. This would allow us to use other Gulp modules more easily.

rollup-plugin-multi-entry throws error when using --watch

I created a simple example, where I'm trying to give multiple entries to rollem with the multi-entry rollup plugin. See the attached rollemtest.zip for the source.

If I execute rollem -c rollup.config.js, then it works fine. If on the other hand I try executing rollem -cw rollup.config.js, it throws the following error (assuming, that I'm standing in the C:\wamp\www\rolluptest\ folder):

path.js:7
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^

TypeError: Path must be a string. Received true
    at assertPath (path.js:7:11)
    at join (path.js:466:7)
    at Object.<anonymous> (C:\wamp\www\rolluptest\node_modules\rollem\bin\rollem.js:11:20)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.runMain (module.js:575:10)
    at run (bootstrap_node.js:352:7)

If I replace rollem with rollup (version 0.41.4), then both codes work without a problem.
See rolluptest.zip for this other case.

Pass plugins list

Allow passing list of plugins

import nodeResolve from 'rollup-plugin-node-resolve'
export default {
  entry: 'src/out-spec.js',
  plugins: [ nodeResolve() ],
  targets: [
    { dest: 'cypress/integration/out-spec.js', format: 'umd' }
  ]
}

File globs would be nice

it would be cool if there where file globs for entry dist setups so you can have

a.js -> a.bundle.js
b.js -> b.bundle.js
c.js -> c.bundle.js

if you want to bundle each file in a folder individually.

Add built time to the console.log in buildBundles function

When the cli is running for a long time, and the output of single build x bundles rows are higher the the max visible row count in the window, there is no visual feedback if the package have been built or still compiling because the console window content will be the "same" visually.

A build (date)time should be added to the message. Eg:

let timeString = new Date().toLocaleString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
console.log('[%s] built %d bundles', timeString, configs.length)

Thoughts?

"npm run e2e" fails on windows

At the beginning of the test, it first tries executing the following command:

cd test/es5-config; npm test

Windows says, that it fails to load this directory. Tested it in MINGW32 (Git Bash) and Windows 7 CMD.

Babel compatibility with rollem.config.js, import vs require

I'm using rollup with rollem. In my rollem.config.js, when running rollem --watch as an npm script, if I import modules like this:

const nodeResolve = require('rollup-plugin-node-resolve');
const babel = require('rollup-plugin-babel');
const uglify = require('rollup-plugin-uglify');

everything works fine. If I do this instead however:

import babel from 'rollup-plugin-babel';
import nodeResolve from 'rollup-plugin-node-resolve';
import uglify from 'rollup-plugin-uglify';

everything still works, but now I get the following warnings:

'rollup-plugin-babel' is imported by rollem.config.js, but could not be resolved – treating it as an external dependency
'rollup-plugin-node-resolve' is imported by rollem.config.js, but could not be resolved – treating it as an external dependency
'rollup-plugin-uglify' is imported by rollem.config.js, but could not be resolved – treating it as an external dependency

As stated, everything works just fine (things get built), but it's still an annoying (and seemingly unecessary) warning.

Cannot generate IIFE or UMD bundles

Error: You must supply options.moduleName for UMD bundles
    at umd (/Users/aminev/dev/funponent/node_modules/rollem/node_modules/rollup/dist/rollup.js:6568:9)
    at Bundle.render (/Users/aminev/dev/funponent/node_modules/rollem/node_modules/rollup/dist/rollup.js:7452:16)
    at Object.write (/Users/aminev/dev/funponent/node_modules/rollem/node_modules/rollup/dist/rollup.js:7637:22)
    at /Users/aminev/dev/funponent/node_modules/rollem/src/index.js:11:21

Feature Request: Wildcard support?

I could be missing something and Rollem already does what I'm looking for, but wildcards would be ideal in the context of building a module for unit testing where each export in a file within a directory is added to a CJS module...

gulp.task "build:module", ->
    rollEm [
       
        entry: "./src/main/js/example/app/**/*/.js"

        format: "cjs"
        dest: "./dist/app.js"
    ]

The wildcard entry ./src/main/js/example/app/**/*/.js would prompt rollem to iterate the directory...

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.