$ npm install --save-dev grunt-jspm-builder
The grunt-jspm-builder provides all jspm production workflows via most SystemJS APIs.
grunt.loadNpmTasks('grunt-jspm-builder');
Build a single monolithic bundle including all 3rd party libraries.
grunt.initConfig({
// ...
jspm: {
monolithicBundle: {
options: {
sfx: true,
minify: true,
mangle: true,
sourceMaps: false
},
files: {
"build/js/app.js": "src/app.js"
}
}
}
// ...
});
Extract all 3rd party dependencies from your project and place them in a separate bundle.
grunt.initConfig({
// ...
jspm: {
extractDeps: {
options: {
sfx: false,
minify: true,
sourceMaps: false,
inject: true, // important for jspm projects only
mangle: true
},
files: {
"build/js/libs/dependencies.js": "js/**/* - [src/**/*]"
}
}
}
// ...
});
Builds the project excluding the specified bundles or source trees using arithmetic and/or module syntax.
grunt.initConfig({
// ...
jspm: {
excludeBundles: {
options: {
sfx: false,
minify: true,
mangle: true,
sourceMaps: false
},
files: {
// Exclude all 3rd party dependencies and mock data from the build.
// This task assumes that build/js/libs/dependencies exists
"build/js/app.js": "js/app - build/js/libs/dependencies - [js/mockData/**/*]"
}
}
}
// ...
});
Build the dependencies in common between 2 modules including all project-level and 3rd party dependencies.
grunt.initConfig({
// ...
jspm: {
createCommon: {
options: {
sfx: false,
minify: true,
mangle: true,
sourceMaps: false,
inject: true // important for jspm builds only
},
files: {
"build/js/common.js": "js/modules/module1 & js/modules/module2"
}
}
}
// ...
});
Compare 2 or more bundles using arithmetic, extract their common dependencies and place them in a separate bundle and then build all the bundles.
grunt.initConfig({
// ...
jspm: {
commonOption2: {
// Options for bundles
options: {
sfx: false,
minify: false,
mangle: false,
sourceMaps: true
},
files: {
// Exclude core-libs from the comparison
// since it is it's own bundle.
"build/modules/module1": "js/modules/module1 - core-libs",
"build/modules/module2": "js/modules/module1 - core-libs"
},
// The 'commonBundle' Object is required in order
// to tell the builder to compare the above source
// trees and create a bundle containing common deps.
commonBundle: {
// options for building the common bundle
options: {
sfx: false,
minify: false,
sourceMaps: false,
inject: true, // important!
mangle: true
},
dest: 'build/js/common.js'
}
}
}
// ...
});
All available options follow those used on SystemJS builds.
Default: true
Creates a single self-executing bundle for a module (Not available using bundle arithmetic).
Default: true
Use minification, defaults to true.
Default: true
Use mangling with minification, defaults to true
Default: false
include or exclude source maps in the build, defaults to false
Default: false
When true, inject the bundle tree into the configuration file. This is especially important when building one or more common bundles.
MIT © Justin Wilaby