$> npm install rc-app-builder --registry "http://deployer1:4873/"
- Constructor Parameters
- (
Object
) config: Configuration options:- (
String
) config.baseDir: The folder from which relative paths in the entry file should be resolved. Specifying this is only necessary if astream.Readable()
is passed toAppBuilder.prototype.build()
. - (
String
) config.baseURL: If the entry HTML file contains a<base>
tag, itshref
will be modified to resolve to thebaseURL
. - (
Boolean
) config.debug: Iftrue
will cause certain plugins to behave differently. For example, the UglifyJS plugin will do nothing. - (
Object
) [optional] config.plugins: Plugins to use.- (
Array
ofString
s) [optional] config.plugins.js: Name of plugin modules for transforming JavaScript. Will be looked-up using Node'srequire()
algorithm relative toconfig.baseDir
. If unspecified, default JS plugins will be used. - (
Array
ofString
s) [optional] config.plugins.css: Name of plugin modules for transforming CSS. Will be looked-up using Node'srequire()
algorithm relative toconfig.baseDir
. If unspecified, default CSS plugins will be used.
- (
- (
- (
- Properties
- (
Object
) config: Theconfig
passed to the constructor. - (
Object
) plugins: The build plugins that will be used:- (
Array
ofString
s): js: Paths to plugin modules for transforming JavaScript. - (
Array
ofString
s): css: Paths to plugin modules for transforming CSS.
- (
- (
- Methods
- build(entry): Builds an app using the configured plugins and inlines all JS and CSS resource into the result.
- Parameters:
- (
String
orstream.Readable
): Either a path to an HTML file, or astream.Readable
representing an HTML document.
- (
- Returns:
- (
stream.Readable
): A stream representing the compiled app HTML file.
- (
- Parameters:
- build(entry): Builds an app using the configured plugins and inlines all JS and CSS resource into the result.
Included by default
This JS plugin will compile all JavaScript assets with browserify.
- (
Object
) config.browserify.options: Options to pass to thebrowserify()
function. - (
Array
ofArray
s) config.browserify.plugins: EachArray
should contain two elements:- (
String
): 0: The name of a browserify plugin module. - (
Object
) [optional] 1: A configurationObject
for the plugin.
- (
- (
Array
ofArray
s) config.browserify.transforms: EachArray
should contain two elements:- (
String
): 0: The name of a browserify transform module. - (
Object
) [optional] 1: A configurationObject
for the transform.
- (
var fs = require('fs');
var AppBuilder = require('rc-app-builder');
var builder = new AppBuilder({
debug: true,
browserify: {
options: {
insertGlobals: true
},
transforms: [
['babelify', {
presets: ['es2015', 'react']
}],
['uglifyify']
]
}
});
builder.build('./my-app.html').pipe(fs.createWriteStream('./my-app--built.html'));
Included by default
This JS plugin will compress all JavaScript assets with UglifyJS.
- (
Object
) config.uglify: Options to pass to theUglifyJS.minify()
method. - (
Boolean
) config.debug: Iftrue
, this plugin will do nothing.
var fs = require('fs');
var AppBuilder = require('rc-app-builder');
var builder = new AppBuilder({
debug: false,
uglify: {
output: {
comments: true,
semicolons: false
},
compress: {
unsafe: true,
warnings: false
}
}
});
builder.build('./my-app.html').pipe(fs.createWriteStream('./my-app--built.html'));
Included by default
This JS plugin will compress all JavaScript assets with UglifyJS.
- (
Object
) config.cleanCSS: Options to pass to theCleanCSS()
constructor. - (
Boolean
) config.debug: Iftrue
, this plugin will do nothing.
var fs = require('fs');
var AppBuilder = require('rc-app-builder');
var builder = new AppBuilder({
debug: false,
cleanCSS: {
aggressiveMerging: false,
keepSpecialComments: true
}
});
builder.build('./my-app.html').pipe(fs.createWriteStream('./my-app--built.html'));
AppBuilder plugins are CommonJS modules that export Function
s. The Function
accepts a number of parameters and is expected to return a stream that emits data (like a stream.Readable
, stream.Duplex
or stream.Transform
.)
- Passed Parameters:
- (
String
) path: The absolute path of the file to be transformed. - (
stream.Readable
) file: A stream representing the file. If your plugin is not first in thebuilder.plugins.js
/builder.plugins.css
Array
, this will be the stream returned by the plugin preceding yours. - (
Object
) config: A deep copy of theAppBuilder
instance'sconfig
. - (
Function
) callback: AFunction
to (optionally) call with anError
when something goes wrong.
- (
Your plugin can then be registered by adding it to the proper plugins
Array
:
var AppBuilder = require('rc-app-builder');
var builder = new AppBuilder();
builder.plugins.js.push(
require.resolve('./path/to/my/plugin'),
require.resolve('module-from-npm')
);