0.1.1 • Published 7 years ago

@niksy/babayaga v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

babayaga

Convenient Browserify builds. Highly experimental.

Features:

  • multiple entry points
  • code splitting
  • common bundles definition
  • bundle and build lifecycle methods
  • streams wrapped with Gulp

Install

npm install @niksy/babayaga --save

Usage

const babayaga = require('@niksy/babayaga');
const build = babayaga({
	entries: {
		bootstrap: './bootstrap.js',
		app: './app.js'
	},
	output: {
		path: './out',
		publicPath: 'http://example.com/'
	},
	paths: [
		'local_modules'
	],
	commonBundles: [
		{
			entry: ['bootstrap'],
			modules: [
				'whatwg-fetch'
			]
		}
	]
}).build();

API

babayaga(opts)

Returns: Object

Prepares build. Returns object with build method which creates build and returns Promise which resolves when build is completed.

opts

Type: Object

cwd

Type: String
Default: process.cwd()

Current working directory of the build.

entries

Type: Object
Default: {}

List of entry points where key is identifier of the entry point and value filename of the entry point.

output

Type: Object
Default: {}

PropertyTypeDefaultDescription
pathString'./'Output path for the build.
publicPathString'/'URL for async bundles.
filenameFunctionMethod to generate bundle filename.
asyncFilenameFunctionMethod to generate async bundle filename.
filename
PropertyTypeDescription
keyStringEntry point key.
fileStringFilename of entry point.
asyncFilename
PropertyTypeDescription
hashStringHash of resolved file.
fileStringFilename of resolved file.
watch

Type: Boolean
Default: false

Should the build watch for changes.

dev

Type: Boolean
Default: false

Should the build be in development mode (e.g. output inline sourcemaps).

verbose

Type: Boolean
Default: false

Should the build output verbose information.

paths

Type: Array
Default: []

See opts.paths.

commonBundles

Type: Object[]
Default: []

List of common bundles and their dependencies. Convenient wrapper arround Browserify multiple bundles.

Following configuration will:

  • have whatwg-fetch module required only in bootstrap entry point
  • have jquery module required only in core entry point

When other entry points and their dependencies require whatwg-fetch or jquery, they won’t get bundled multiple times, but instead will be referenced from bootstrap or core entry point respectively.

{
	entry: ['bootstrap'],
	modules: [
		'whatwg-fetch'
	]
},
{
	entry: ['core'],
	modules: [
		'jquery'
	]
}
asyncRequireLoaderEntry

Type: String[]
Default: ['']

Which entry point should be considered as async require loader entry point.

asyncRequireOptions

Type: Object
Default: {}

Async require options.

collapserPreset

Type: String[]
Default: []

Preset list for bundle collapser.

verboseLog

Type: Function

Output verbose log.

PropertyTypeDescription
fileStringFile which generated log.
messageStringLog message.
onError

Type: Function

Error callback.

PropertyTypeDescription
errErrorBuild error.
setupBundle

Type: Function

Method to additionally setup Browserify bundle. It should return original or modified bundle instance.

PropertyTypeDescription
bundleBrowserifyBrowserify bundle instance.
optsObjectAdditional options.
onStartWrite

Type: Function

Method to call when bundle starts writing to filesystem. It should return original or modified stream.

PropertyTypeDescription
streamStreamBundle stream.
isAsyncTaskBooleanIs bundle stream async require stream.
isWatchUpdateBooleanIs current callback inside watch update mode.
onBeforeWrite

Type: Function

Method to call before bundle gets written to filesystem. It should return original or modified stream.

PropertyTypeDescription
streamStreamBundle stream.
isAsyncTaskBooleanIs bundle stream async require stream.
isWatchUpdateBooleanIs current callback inside watch update mode.
onAfterWrite

Type: Function

Method to call after bundle gets written to filesystem. It should return original or modified stream.

PropertyTypeDescription
streamStreamBundle stream.
isAsyncTaskBooleanIs bundle stream async require stream.
isWatchUpdateBooleanIs current callback inside watch update mode.
onStartBuild

Type: Function

Method to call when build starts writing to filesystem. It should return original or modified stream.

PropertyTypeDescription
streamStreamBuild stream.
isAsyncTaskBooleanIs build stream async requires stream.
onBeforeBuild

Type: Function

Method to call before build gets written to filesystem. It should return original or modified stream.

PropertyTypeDescription
streamStreamBuild stream.
isAsyncTaskBooleanIs build stream async requires stream.
onAfterBuild

Type: Function

Method to call after build gets written to filesystem. It should return original or modified stream.

PropertyTypeDescription
streamStreamBuild stream.
isAsyncTaskBooleanIs build stream async requires stream.

License

MIT © Ivan Nikolić