NOTE: This library is not maintained anymore. If you want a much better solution for JavaScript bundling, use Webpack
Grunt plugin for asset-smasher
See the asset-smasher homepage for more details on usage of asset-smasher and how it works.
This plugin requires Grunt ~0.4.1
and asset-smasher ~0.3.0
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-asset-smasher --save-dev
One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-asset-smasher');
In your project's Gruntfile, add a section named asset_smasher
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
asset_smasher: {
options: {
// asset-smasher options go here
},
dist: {
}
},
})
Type: String
Default value: No Default. This must be specified
The directory to output assets into
Type: String[]
Default value: [process.cwd()]
An array of asset paths
Type: String[]
Default value: ['**/*.*']
Array of glob patterns for assets that should be output (other assets will be filtered out/not processed)
Type: String
Default value: ''
Prefix to append to logical paths when constructing urls. use if output dir is not served from the root of your web app
Type: Boolean
Default value: false
Whether to compress JavaScript and CSS assets
Type: Boolean
Default value: false
Whether to output copies of the final assets with an MD5 hash of the contents appended to the file name (e.g. myasset-xxxxxxxxxxxxxxxxxxxx.js)
Type: Boolean
Default value: false
Whether to output a copy of the final assets gzipped
Type: String
Default value: 1.0
Change this value if you want to invalidate all of your assets (the version is included when computing the hash value for an asset)
Type: Object
Default value: {}
Helpers/values to pass into transformers (e.g. the ejs
transformer exposes these as local variables)
Type: Boolean|Object
Default value: false
Whether to enable AMD module support. Either a boolean can be passed in, or an object of the form
{
baseLogicalPath: 'base/path' // The value defaults to '' and will be stripped off of all logical paths before constructing module ids
}
Type: Boolean
Default value: false
Whether verbose information should be printed out to stdout when compiling
Type: Boolean
Default value: false
Whether to prevent deletion of the output directory before compilation
This will compile all files in my/assets
and output them to output/dir
grunt.initConfig({
asset_smasher: {
options: {
paths: ['my/assets'],
outputTo: 'output/dir'
}
},
})
This compiles only the manifest files in several asset paths, compresses the result, and creates hashed versions of the files.
grunt.initConfig({
asset_smasher: {
options: {
paths: ['my/assets', 'my/otherassets'],
outputTo: 'output/dir',
only: ['**/*.mf'],
prefix: 'assets',
compress: true,
hash: true
}
},
})
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Initial release - Compatible with asset-smasher
0.3.x