Coder Social home page Coder Social logo

broccoli-dist-es6-module's Introduction

broccoli-dist-es6-module

Build Status

demo

Author your library in ES6 modules and distribute in everything under the sun:

  • cjs
  • amd
  • amd, named & concatenated
  • globals, concatenated

Installation

$ npm install broccoli-dist-es6-module

Usage

// give it a tree and some options:
makeModules('broccoli-dist-es6-module')(tree, {
  main: 'index',
  global: 'MyLib',
  packageName: 'my-lib',
  shim: {
    'jquery': 'jQuery'
  }
});

Sample Brocfile.js:

var makeModules = require('../../index');

module.exports = function(broccoli) {

  // make a tree from your source files
  var src = broccoli.makeTree('lib');

  return makeModules(tree, {

    // the entry script, and module that becomes the global
    main: 'index',

    // will become window.MyLib with the exports from `main`
    global: 'MyLib',

    // the prefix for named-amd modules
    packageName: 'my-lib',

    // global output only: naive shimming, when the id 'jquery' is imported,
    // substitute with `window.jQuery` instead
    shim: {
      'jquery': 'jQuery'
    }
  });

};

And then run broccoli:

$ broccoli build dist

Open up dist to see the results.

Options

  • main - the entry script to your package, determines which module exports to your global namespace, also the package that is returned in AMD with require(['your-package-name'])

  • packageName - named-amd, the name of your package require(['your-package-name']);

  • global - globals: the global to attach your main module to

  • shim - globals: map import string ids to objects on window, see usage above or the examples

Notes

  • This uses the compatFix option of the es6-module-transpiler which is not necessarily future proof (but without it we couldn't import jQuery from 'jquery').

  • The shimming is really hacky, but its working.

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.