A Yeoman generator for creating universal JavaScript modules that work everywhere using ES2015, Babel, Webpack, Mocha, Chai, Sinon, Karma, Isparta, and ESLint
- ES2015 - Universal JavaScript Module Boilerplate (UJSM) uses Babel to transpile ES2015 source code. There are several reasons to use ES2015 alongside with transpilation (instead of plain Node >= 4):
- The transpiled code will work with legacy Node versions;
- Since we're going to run this module in the browsers, it will be necessary to provide cross-browser compatibility;
- Seamless migration after you decide to drop 0.x.x support;
- ES2015 Tests - Mocha flag
--compilers js:babel-core/register
(it's already preconfigured in the npmnpm run test-server
script) allows to transpile Mocha tests written with ES2015 on the fly. - Universal Tests - UJSM uses Karma to make sure that code works in the browser. A npm script
test-browser
does the job. Feel free to run the same tests in both environments - it can be preconfigured by answeringNo
onWould you like to keep your server/client tests separate?
question during generator initialization. - UMD - Webpack is preconfigured to integrate the Universal Module Definition (UMD) API (which provides compatibility with the most popular script loaders) to the ouput script.
- TDD - The package has a particular npm script
npm run tdd
(andnpm run tdd-browser
for the browser testing) to start a Mocha watch task that reruns tests on file changes. - Git Hooks - Every time before commiting, husky runs npm tasks conveniently configured in the package.json (in this case it automatically starting both
test
andbuild
tasks). You can temporary disable this feature by adding--no-verify
flag (i.e$ git commit -am "Beep bop" --no-verify
). The list of all available hooks can be found here.
# Install Yeoman and the UJSM generator globally
$ npm install -g yo generator-universal-module
# Make a new folder & open it
$ mkdir my-shiny-module && cd $_
# Run the generator
$ yo universal-module
npm run build
- Build task that generates both minified and non-minified scripts;npm run test-server
- Run Mocha tests once;npm run test-browser
- Run Mocha tests in the browser using Karma once;npm run test
- Shortcut fornpm run test-server && npm run test-browser
;npm run tdd
- Run Mocha tests & watch files for changes;npm run tdd-browser
- Run Karma (w/ Mocha) tests & watch files for changes;npm run coverage
- Run Isparta, a code coverage tool;
ujsm - The original boilerplate;
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT
HON env variable
http://stackoverflow.com/questions/21365714/nodejs-error-installing-with-npm
Error: EPERM, operation not permitted 'C:\...\node_modules\phantomjs\tmp\phantomjs-1.7.0-windows'
$ npm cache clean
MIT © Philipp Alferov