Giter VIP home page Giter VIP logo

common-bundler's Introduction

common-bundler

Creates a common package from a collection of scripts

Getting Started

$ npm i -D common-bundler

Example

The bundler is a little opinionated about how you structure your scripts but something like this is a good start:

.
└── src
    ├── bundles
    │   ├── bundleA
    │   │   ├── bundleADep.js
    │   │   └── main.js
    │   └── bundleB
    │       └── main.js
    └── common
        └── menu.js

Now just let the bundler do its thing

$ bundler src/bundles -o dist

The bundler will give you some info about what its doing and you’ll end up with a few scripts to include in whichever pages you want, this will let you include just what the page needs to work and not drag around kb of dependency unless you need them

.
└── dist
    ├── bundleA.js
    ├── bundleB.js
    └── common.js

In general you’ll need common and whichever bundle you need in a page, making sure common goes in first.

<script src="dist/common.js"></script>
<script src="dist/bundleA.js"></script>

Use npm scripts

You can use it a global module, but that kind-of sucks so add the build process to your npm scripts object in your package.json

{
    "scripts": {
        "build:scripts": "bundler src/bundles -o dist"
    }
}

Then let npm execute it

$ npm run build:scripts

API

Check the help to see the full list of options

$ bundler -h

-t --transform

Adds a transform to the browserify pipeline

Feel free to add multiple transforms, as usual the order is important

Note that there is generally no need to pass uglify, omitting the debug flag will tell the bundler to uglify up the scripts, currently just uses UglifyJS

$ bundler src/bundles -o dist -t flowcheck -t babelify

-d --debug

Sticks browserify into debug mode which leaves the build unminified and gives you source maps too

Having unminified and source maps is useful for something like babel that transpiles code as you’ll have access to human-readable transpiled code and the ES6 version that you’re writing

$ bundler src/bundles -o dist -d

--watch

Select a glob of files to watch for changes and run a build when they are updated

npm will tend to expand globs so specify it as a string and it’ll get passed through to glob and that’ll give a list of files to chokidar

To try and make sure the build isn’t stale the watcher will always try to fire a new bundle on save unless it’s already working, whereby it’ll wait until it’s finished and run a build sequentially to stop multiple builds if you’re saving quickly or updating multiple files concurrently.

$ bundler src/bundles -o dist --watch 'src/**/*.js'

-c --config

Specifies a configuration file to set up browserify

You can specify a custom file (such as .bundlerrc) if you like but using package.json will work just as well, just add a bundler key to your package config and they’ll get passed to browserify.

...,
"bundler": {
  "extensions": [
    ".js",
    ".jsx"
  ]
},
...
$ bundler src/bundles -o dist -c package.json

Enjoy responsibly!

common-bundler's People

Contributors

mattstyles avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  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.