Utilize modules-webmake to auto bundle all CommonJS/Node.js pacckages for web browser
Auto bundle CommonJS/Node.js packages for web browsers.
Webassemble utilize Webmake to automatically bundle all CommonJS/Node.js packages to share them for the browser.
The reason of building this is that Webmake needs an JS package as entry point whose exported properties can be shared to the browser and so the responsibility of Webassemble is to automatically collect all exported properties from all JS packages you would like to share to browser as the input for Webmake. You can think of Webassemble is the preprocessor for Webmake.
For example, I have two utility classes would like to share between my Node.js application and browser processing.
'use strict';var StringUtil = require'./string-util.js'StringUtil;var DateUtil =returnDATE_FORMAT: 'yy' + DATE_ELEMENT_SEPARATOR + 'mm' + DATE_ELEMENT_SEPARATOR + 'dd'if StringUtilisBlankdatereturn null;return datesplit' '0;;;exportsDateUtil = DateUtil;
'use strict';var StringUtil =returnreturn str === null || typeofstr === 'undefined' || strlength === 0;;;exportsStringUtil = StringUtil;
If I use the date-util.js as input for Webmake, only DateUtil will be exported. If I would like to export StringUtil too, I need to explicitly write a dummy package to requre and export both DateUtil and StringUtil.
Webassemble is made to write the dummy package for you.
Let's say if you would like to export above two packages to a file named bundles.js, you can execute below command:
$ webassemble date-util.js string-util.js bundles.js
It will generate a preprocess file as below. This file is actually the input file for Webmake.
exportsDateUtil = require'./date-util';exportsStringUtil = require'./string-util';
$ npm install -g webassemble
$ webassemble <input> <output> [options]
input - JS package files to be included in the preprocess file for Webmake. Can be multiple.
output - Output filename.
options - All options Webmake can accept and some extra options listed below.
Only return the preprocess file content without
Only write the preprocess file content without calling webmake
webassemblesrcFiles destFile options;
If no destFile is provided or returnContentOnly is set to be true, the preprocess file content will be returned.
$ npm test