GithubHelp home page GithubHelp logo

aeberdinelli / bundlerj Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 18 KB

A simplified javascript bundler to generate a single file with all the app dependencies.

JavaScript 100.00%
node es6 bundler minify uglifyjs

bundlerj's Introduction

Bundler JS (bundlerj)

A simplified javascript bundler to generate a single file with all the app dependencies

Options

The bundler receives parameters within an object, here's an example:

const options = {
	/**
	 * The source to get your files from.
	 * You can use a string with a folder name or an array with folders
	 */
	"files": "src/",

	/**
	 * The route to the destination file
	 */
	"output": "dist/app.packed.js",

	/**
	 * You can add blacklist rules which will be translated into regex to ignore certain files
	 */
	"blacklist": [
		// If you have angular libs, you can ignore those from your packed app
		"^(.*)angular-(.*)$", 
		
		// Let's say you want to ignore all html or xml files
		"^(.*)\\.(html|xml)$" 
	],

	/**
	 * This puts every JS file content into an anonymous function.
	 * You should consider using this if you have several variables with the same names around more than one file.
	 * For example:
	 * 
	 * (function() {
	 *     console.log('Hello world');
	 * })();
	 */
	"isolate": true,

	/**
	 * Give some feedback to the console while creating the bundle
	 */
	"debug": true
}

Install

Just run:

npm install --save-dev bundlerj

You can install it globally for using CLI in several proyects too:

npm install -g bundlerj

Usage

CLI

Some command line options are available.

Usage: bundler [options] [command]

Options:
  -V, --version           output the version number
  -g, --config <file>     Ignores everything else and uses a config file instead
  -f, --source <folders>  Specify the folder to get the source files from
  -o, --output <output>   Specify the full path to the output file, including name
  -i, --isolate           Puts every file content inside an anonymous function
  -s, --sort              Sort the file paths alphabetically before creating the bundle
  -p, --progress          Show progress
  --ignore-charset        Do not try to get the file charset (assumes everything is UTF-8, improves speed)
  -h, --help              output usage information

Commands:
  generate                Generates the bundled javascript file
  clear                   Clears the output file
  help [cmd]              display help for [cmd]

For example:

bundle generate --source src/js --output dist/bundle.js --progress

Using the available method

const bundle = require('bundlerj');

const SETTINGS = {
	// Your settings here
};

bundle(SETTINGS);

Using gulp

You may setup a gulp task in order to build your bundle every time a file is updated:

const gulp = require('gulp');
const bundler = require('bundlerj');

gulp.task('bundle-js', function() {
	bundler({
		// Settings
	});
});

gulp.task('default', ['bundle-js'], function() {
	gulp.watch('./src/js/**/*.js', ['bundle-js']);
});

That will watch changes in your src/js folder and then run the bundler.

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.