grunt-bundle-jsnext-lib
raw JSON → 0.5.0 verified Fri May 01 auth: no javascript deprecated
Grunt plugin to bundle ES6 modules into a single file for browsers or CommonJS for Node.js. Version 0.5.0 is the latest stable release (last updated 2017). Relies on es6-module-transpiler and a custom npm resolver. Differentiators: supports jsnext:main for publishing ES6 modules via npm, multiple output formats (bundle, CJS, system.register), and source maps. Development has been inactive since 2017; consider modern alternatives like rollup or webpack.
Common errors
error Warning: Task "bundle_jsnext" not found. ↓
cause grunt.loadNpmTasks not called or package not installed.
fix
Ensure grunt.loadNpmTasks('grunt-bundle-jsnext-lib') is in Gruntfile and npm install grunt-bundle-jsnext-lib --save-dev is run.
error Fatal error: Unable to write destination file "dest/path/" (code: EISDIR). ↓
cause Using bundle_jsnext but dest points to a directory instead of a file.
fix
Change dest to a file path (e.g., 'dist/library.js') for bundle_jsnext.
error Error: Cannot find module 'es6-module-transpiler' ↓
cause Missing dependency es6-module-transpiler.
fix
Run npm install es6-module-transpiler --save-dev alongside this plugin.
Warnings
deprecated Project is unmaintained since 2017; no support for modern ES module syntax or newer Grunt versions. ↓
fix Migrate to a modern bundler like Rollup, Webpack, or Babel.
breaking As of v0.2.0, UMD format was removed; only 'bundle' and 'cjs' formats are supported. ↓
fix Use bundle_jsnext for browser global or cjs_jsnext for CommonJS. No UMD output.
gotcha dest must be a file for bundle_jsnext task, but a directory for cjs_jsnext task. ↓
fix Ensure dest is a file path for bundle_jsnext and a directory path for cjs_jsnext.
deprecated Depends on es6-module-transpiler which is no longer maintained. Use of esprima-fb may cause compatibility issues with modern Node.js. ↓
fix Switch to a transpiler that supports ES modules natively.
Install
npm install grunt-bundle-jsnext-lib yarn add grunt-bundle-jsnext-lib pnpm add grunt-bundle-jsnext-lib Imports
- grunt.loadNpmTasks wrong
const bundleJsnext = require('grunt-bundle-jsnext-lib');correctgrunt.loadNpmTasks('grunt-bundle-jsnext-lib'); - bundle_jsnext wrong
grunt.registerTask('bundle', 'grunt-bundle-jsnext-lib');correctgrunt.initConfig({ bundle_jsnext: { ... } }); - cjs_jsnext wrong
cjs_jsnext: { dest: 'lib/' }correctgrunt.initConfig({ cjs_jsnext: { library: { options: { main: 'src/main.js' }, dest: 'lib/' } } });
Quickstart
// Install: npm install grunt grunt-bundle-jsnext-lib --save-dev
// Gruntfile.js
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-bundle-jsnext-lib');
grunt.initConfig({
bundle_jsnext: {
library: {
options: {
namespace: 'MyLib'
},
dest: 'dist/my-lib.js'
}
},
cjs_jsnext: {
library: {
dest: 'lib/'
}
}
});
grunt.registerTask('default', ['bundle_jsnext', 'cjs_jsnext']);
};