Code Monkey home page Code Monkey logo

broccoli-rollup's Introduction

broccoli-rollup

Build Status

A broccoli plugin that uses rollup.js on its input.

Usage

Basic

// Brocfile.js
import rollup from 'broccoli-rollup';

export default () =>
  rollup('lib', {
    // nodeModulesPath: string Defaults to process.cwd()
    rollup: {
      input: 'index.js',
      output: {
        file: 'bundle.js',
        format: 'es',
      },
    },
  });

Code Splitting

// Brocfile.js
import rollup from 'broccoli-rollup';

export default () =>
  rollup('lib', {
    // nodeModulesPath: string Defaults to process.cwd()
    rollup: {
      input: 'index.js',
      output: {
        dir: 'chunks',
        format: 'es',
      },
    },
  });

Multiple Output

// Brocfile.js
import rollup from 'broccoli-rollup';

export default () =>
  rollup('lib', {
    // nodeModulesPath: string Defaults to process.cwd()
    rollup: {
      input: 'index.js',
      output: [
        {
          file: 'my-lib.amd.js',
          format: 'amd',
        },
        {
          file: 'my-lib.iife.js',
          name: 'MyLib',
          format: 'iife',
        },
      ],
    },
  });

Notes and Caveats

Broccoli is designed around immutable input and although rollup does expose enough in the build output for us to write it to disk, this doesn't work with the onwrite plugin hook and requires a significant amount of code to get feature parity with rollup's buildOutput.write(outputOptions).

We use the following build flow to achieve compatibility and feature parity with rollup's cli while still adhering to broccoli's immutable input constraints.

  1. sync node.inputPaths[0] to ${node.cachePath}/build
  2. symlink options.nodeModulesPath to ${node.cachePath}/node_modules
  3. change the working directory to ${node.cachePath}/build (rollup doesn't allow this to be passed in and plugins may also the use cwd)
  4. run rollup
  5. restore the working directory
  6. sync ${node.cachePath}/build to node.outputPath for all files that are different from the input.

If you have any plugins that require hard-coded paths into node_modules, please note that node_modules is symlinked above the build path.

So instead of doing node_modules/x you need to do ../node_modules/x.

broccoli-rollup's People

Contributors

chadhietala avatar krisselden avatar stefanpenner avatar turbo87 avatar bryancrotaz avatar ryanone avatar ahx avatar topaxi avatar dwickern avatar villander avatar whastings avatar zackthehuman avatar bekzod avatar

Watchers

Robert Jackson avatar James Cloos avatar  avatar

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.