Builder for creating distributable JavaScript files from source. Concatenate, wrap, uglify.
Builder for creating distributable JavaScript files from source. Concatenate, wrap, uglify.
Requires NodeJS to run.
Then install buildify via npm:
npm install buildify
Create a file with your build script (see the example in 'Usage' below), call it something like
build.jsand then run it with:
node build.js
var buildify = require('buildify');buildify() .load('base.js') .concat(['part1.js', 'part2.js']) .wrap('../lib/template.js', { version: '1.0' }) .save('../distribution/output.js') .uglify() .save('../distribution/output.min.js');
Create a new Builder instance.
Takes the starting directory as the first argument, e.g. __dirname. If this is not set, the current working directory is used.
Options: -
interpolateUnderscore template settings. Default to mustache {{var}} style interpolation tags. -
encodingFile encoding (Default 'utf-8') -
eolEnd of line character (Default '\n') -
quietWhether to silence console output
Set the current working directory.
Change the current working directory.
Set the content to work with.
Get the current content. Note: breaks the chain.
Load file contents.
Concatenate the content of multiple files.
buildify() .concat(['file1.js', 'file2.js']);
Wrap the contents in a template.
Useful for creating AMD/CommonJS compatible versions of code, adding notes/comments to the top of the file etc.
By default the template uses Mustache-style tags and has a special tag,
{{body}}which is where the contents are placed.
Other custom tags can be included and passed in the
dataargument.
//template.js /* * This is a module for doing stuff. * Version {{version}}. */ (function() { //Setup code can go here{{body}}
});
//build.js buildify() .load('src.js') .wrap('template.js', { version: '1.0' });
Perform a function on the content. The content is set to what the function returns.
buildify() .load('src.js') .perform(function(content) { return content.replace(\assetpath\g, 'http://cdn.example.com'); });
Minimise your JS using uglifyJS.
Options: - mangle: Whether to mangle output from UglifyJS. Default: true
Minimise your CSS using clean-css. Optionally a line break is inserted after 'maxLineLength' characters in the minimized css file.
Save the contents to a file.
Reset/clear contents.
Buildify supports tasks, allowing to separate a build script in different sections. Dependencies can be specified between tasks. By specifying tasks names as command line arguments, buildify will only run the specified tasks, taking into account their dependencies
For example create a script named
buildify.jswith the following contents: ```js var buildify = require('buildify');
buildify.task({ name: 'task2', depends: ['task1'], task: function () { console.log('task2...'); } });
buildify.task({ name: 'task1', task: function () { console.log('task1...'); } }); ```
To run all tasks, just run the script:
sh node buildify.js
To run a specific task, specify the task name as command line arguments.
sh node buildify.js concat
Create a task.
Options: -
nameA string containing the task name -
descAn optional description of the task -
dependsAn optional string or an array with strings containing the name(s) of tasks which this task depends on. -
task: The function to be executed as task, doing the actual work. Optional.
When installed globally, the command line application
buildifyis available. Running
buildifywill execute the script named
buildify.jsin the current directory (typically the root of a project).
buildify [tasks]
Optionally, a list of task names can be provided to only execute specified tasks. If no tasks are provided, buildify will run the script including all tasks.
0.4.0 Implemented tasks (josdejong)
0.3.1 Fix mangling (can be disabled with mangle: false option in uglify()) (powmedia, whadar)
0.3.0 Add cssmin() for minifying CSS (RustyMarvin) Fix tests under Windows (RustyMarvin)
0.2.0 Add perform() for custom functions (trevorgerhardt)