Isomorphic boilerplate written in ES2015 for Node and the browser.
![Dependency Status](https://david-dm.org/kflash/trolly.svg)
A boilerplate for creating isomorphic libraries using Babel, Webpack, Mocha, Chai, Karma, Isparta, and ESLint
Features
- Babel for ES6 and ES7
- Universal unit tests that work in Node and in the browser
- Support for ES2015 in the unit tests
- Webpack for bundling
- Eslint to maintain a consistent code style
- UMD pattern, which provides compatibility with the most popular script loaders, to the output.
- Isparta for coverage report
- Node >= 4.x
Basic guide
Write your code in src. The entry file is what you named the project in kebab case (although the filename can be changed).
Run webpack
to build a non-minified version of the library.
Put your unit tests in the __tests__
folder. The npm test command runs the tests using Node.
Workflow
npm run build
- Build task that generates minified scriptsnpm run prepublish
- Lint the source, run unit tests, and generate a minified scriptnpm run lint
- Lint the source and unit testsnpm run clean
- Remove the coverage report and the dist foldernpm run karma:browser
- Runs the unit tests with karma and Chrome oncenpm run karma:chrome
- Runs the unit tests with karma and Chrome oncenpm run karma:firefox
- Runs the unit tests with karma and Firefox oncenpm run karma:ie
- Runs the unit tests with karma and Internet Explorer oncenpm run karma:legacy
- Runs the unit tests with karma and Internet Explorer 9.0 oncenpm run karma:all
- Runs the unit tests with karma and Chrome, Firefox and Internet Exploreroncenpm run karma:server
- Runs the unit tests with karma and PhantomJS oncenpm run karma:watch
- Run Karma tests & watch files for changesnpm run mocha:browser
- Runs the unit tests together with the spec runner ( open port 8080 in the browser)npm run mocha:server
- Runs the unit tests on the server oncenpm run mocha:watch
- Run Mocha tests & watch files for changesnpm run coverage
- Run Isparta, a code coverage tool;npm run packages
- Shows all installed dependenciesnpm run package:purge
- Remove all dependenciesnpm run package:reinstall
- Reinstall all dependenciesnpm run package:updates
- Generate a list overview for newer dependenciesnpm run package:upgrade
- Automaticly upgrade all dependencies and update package.json
Unit tests
This project uses Mocha to run your unit tests, it uses Karma as the test runner, it enables the feature that you are able to render your tests to the browser (e.g: Firefox, Chrome etc.).
To run the tests in the project, just simply run npm karma:browser
. If you have Chrome installed, it will be automatically launched as a test service for you. PhantomJs are used to run karma server side. Just simply run npm karma:server
To keep watching your test suites that you are working on, simply do run npm karma:watch
for client side. Or run npm mocha:server
to keep watching the unit tests on the server.
Browser Tests
The browser spec runner can be opened in a browser to run your tests. For it to work, you must first run npm run mocha:browser
, and
then open port 8080 in your browser. Example: localhost::8080
Coveralls
This library is set up to integrate with Coveralls, and will automaticly publish your coverage report if you have created an account for your repo at coveralls.io
Linting
This boilerplate uses ESLint to lint your source. To change the rules, edit the .eslintrc file in the root directory, respectively.
Installation
Download the package, and run this from the command line:
npm install
Customizing
This boilerplate is easily customizable. Add your dependencies to the package.json file, and modify either the webpack config files or the karma files itself.
For the server side unit tests with mocha, you may want to install jsdom etc. This can be done if you modify the bootstrap.js
file located inside the __tests__/setup folder
FAQ
###Help! It doesn't work on Windows! What do I do?
Just take a cup of coffee and relax. It works!
What's the browser compatibility?
As a rule of thumb, this transpiler works best in IE9+. You can support IE8 by limiting yourself to a subset of ES2015 features. The Babel caveats page does an excellent job at explaining the nitty gritty details of supporting legacy browsers.
License
MIT © Kenny Flashlight