Giter Club home page Giter Club logo

cbuild's Introduction

cbuild

build status dependency status npm version

cbuild allows publishing leaner SystemJS-based apps and packages running without build tools. npm itself can pull all required frontend and backend dependencies.

Normally you would use jspm which also users of your package must install. It's very powerful but has some drawbacks if plain npm is enough for your use case:

  • jspm pulls another over 90 packages and 15 megabytes of code with it.
  • ... downloads another separate copy of all required Node.js modules into a different directory structure.
  • ... involves a large config.js, parts of which are manually edited (so belong to version control) and other parts autogenerated from package.json fields (so preferably omitted from version control).

cbuild instead uses Node.js module resolution to find packages installed using npm without additional configuration. Only the manually edited parts are needed in config.js.

How does it work?

cbuild simply passes your SystemJS config.js to systemjs-builder, which bundles your main JavaScript file with its dependencies. cbuild adds a hook to look up any missing files using browser-resolve.

That means you can still use jspm as before but you don't have to reinstall all your npm packages with it, because cbuild also automatically looks inside node_modules. Simple package deduplication is natively handled by npm@3 or the dedupe command in npm@2.

For more complicated scenarios, the full power of SystemJS is still available for loading and bundling.

cbuild supports the browser field in package.json. It can also generate a minimal config.js for SystemJS to load packages without having to bundle them.

Usage

Add in the scripts section of your package.json:

  "scripts": {
    "cbuild": "cbuild"
  }

Then run the commands:

npm install --save-dev cbuild
npm run cbuild -- -o bundle.js

This generates a new file bundle.js with all code required to load the file defined in the browser (or main if browser is missing) field of package.json. You can also set the file on the command line with the --source option.

Run npm run cbuild -- --help to see the command line options:

  Usage: cbuild [options]

  SystemJS node module bundling tool

  Options:

    -V, --version                output the version number
    -b, --builder-config <file>  specify SystemJS builder configuration file
    -d, --debug [flag]           use development environment
    -m, --map <package>          add package to mappings
    -s, --source <file>          main JavaScript source to bundle
    -p, --package <path>         directory with package.json and config.js
    -o, --out <file>             write output bundle to file
    -C, --out-config <file>      write path mappings to new config file
    -I, --include-config <file>  merge another file into new config file
    -q, --quiet [flag]           suppress terminal output
    -v, --verbose [flag]         print dependency tree of bundled files
    -x, --static [flag]          create static (sfx) bundle
    -h, --help                   output usage information

The --builder-config option accepts a JSON file containing SystemJS builder bundle options and SystemJS configuration options structured like:

{
	// Bundle options, for example:
	"minify": true,

	"config": {
		// Configuration options, for example:
		"buildCSS": false
	}
}

API

Docs generated using docts

Interface Branch

Dependency tree branch, used for makeTree() output.
Source code: <>

Properties:

.0? string
File name.

Interface BuildItem

systemjs-builder diagnostics for a single input file.
Source code: <>

Properties:

.name string
.path string
.metadata { [key: string]: any; }
.deps string[]
List of imports.
.depMap { [name: string]: string; }
Table mapping imports to their paths inside the bundle.
.source string
.fresh boolean
.timestamp number
.configHash string
.runtimePlugin boolean
.pluginConfig any
.packageConfig any
.isPackageConfig any
.deferredImports any

Interface BuildOptions

Options object for the build function.
Source code: <>

Properties:

.debug? boolean
If true, set NODE_ENV to development.
.sfx? boolean
If true, create static (sfx) bundle.
.bundlePath? string
Bundled file to output.
.sourcePath? string
Main source file to bundle.
.outConfigPath? string
Output config mapping other package names to their main source files.
.mapPackages? string[]
Map additional packages in output config.

Interface BuildResult

systemjs-builder diagnostics for the entire bundle.
Source code: <>

Properties:

.source string
Bundled output file contents.
.sourceMap string
.modules string[]
List of bundled files.
.entryPoints string[]
List of files intended to be imported from the bundle(?).
.tree { [path: string]: BuildItem; }
.assetList any
Other non-JavaScript files included in the bundle.
.bundleName string

Function build

Bundle files from package in basePath according to options.
Source code: <>

build( ) Bluebird<BuildResult> <>
 ▪ basePath string
 ▫ options? BuildOptions

Function makeTree

Extract a dependency tree from the build function result object.
Returns a nameless root item.
Each item is a list of a file name and its child items.
Uses Breadth-First Search to print shortest import chain to each file.
Source code: <>

makeTree( ) Branch <>
 ▪ result BuildResult

License

The MIT License

Copyright (c) 2016-2018 BusFaster Ltd

cbuild's People

Contributors

jjrv 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

direktspeed

cbuild's Issues

Building with xlsx npm module fails

I run into this yesterday:

> cbuild -d -v -m systemjs-hot-reloader -o dist/bundle.js -C config-npm.js

Bundling for development (NODE_ENV = undefined and --debug set)

Build error:
Error on fetch for fs.js at file:///Users/jta/tmp/hierarchicaltable-example-app/fs.js
	Loading node_modules/xlsx/xlsx.js
	Loading node_modules/makeMaps/dist/ui_components/import_wizard/FileUploadView.js
	Loading node_modules/makeMaps/dist/ui_components/import_wizard/LayerImportWizard.js
	Loading node_modules/makeMaps/dist/MakeMaps.js
	Loading dist/index.js
	Error: ENOENT: no such file or directory, open '/Users/jta/tmp/hierarchicaltable-example-app/fs.js'
    at Error (native)

I believe the module https://github.com/SheetJS/js-xlsx is the culprit. It would seem cbuild doesn't see node's internal modules correctly and tries to find them in the project folders?

I can make a complete test case later if you wish, but wanted to report this already...

Support for reloading changes in node_modules

I have a use case of developing an app and a library separately.

However, reloader does not reload files when they change if they are not under src.

I tried using module level node_modules, since node and TypeScript support loading libraries from importing module's folder under node_modules folder.

However config reloader doesn't check there when finding imported paths, and I couldn't get that part working.

So, I have a structure like this:

/node_modules/[for regular libraries]
/src/[my app files]
/src/node_modules/my_library

Is there any way to either get cbuild to check also source folder's node_modules or config reloader to reload also regular node_modules files?

Gitter

Would you mind jumping on Gitter. I have a collaboration idea I want to run by you. I've sent you a PM

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.