nason / universal-npm-starter

Boilerplate for a NPM package for the node and browser using ES2015

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

universal-npm-starter

Build Status Libraries.io for GitHub Coverage Status NPM version NPM downloads MIT License

Sauce Test Status

Boilerplate for a NPM package for the node and browser

Introduction

Replace this with your package's details!

Starter Intro

This is a boilerplate npm module that can be used to create a universal JavaScript module for node and browser runtimes. It uses rollup to bundle ES2015 code.

The implementation in this boilerplate generates a module thats is distributed perfectly symmetrically, meaning the exact same code is bundled for and executed in node and the browser.

This toolchain can also generate an asymmetrical package with runtime-specific bundles. This involves a few steps:

  • modifying the the rollup config
  • updating package.json with a browser property
  • creating browser and node entry files
  • maintaining API contracts between all entry files

See we-js-logger for an example of an asymmetrical package.

Usage

Clone this repo and replace the code in the src/ and test/ directories with your module. Make it your own. PRs are always welcome :)

Testing

Tests are run via mocha in node, and via karma, webpack and mocha for browsers (PhantomJS by default, but Karma is quite configurable).

This package is also preconfigured for Travis and Sauce Labs. To enable this:

  1. Setup travis-ci for your repository
  2. Add SAUCE_USER_NAME and SAUCE_ACCESS_TOKEN keys to the travis job

Examples

This boilerplate was developed while creating a few modules at WeWork:

Development

  1. Checkout this repo
  2. Run npm install
  3. Make changes in a feature branch and open a PR to master

In lieu of a formal style guide, please:

  • follow the conventions present in the codebase
  • respect the linter
  • keep tests green
  • maintain test coverage

Installing an EditorConfig plugin is also nice.

npm scripts

Target Behavior
npm test Runs tests in browser and node runtimes
npm run tdd Runs tests, bundles and re-runs on file changes
npm run test:coverage Runs tests and outputs a code coverage report to /coverage
npm run test:ci Runs tests, outputs code coverage
npm run lint (Run as a git pre-commit hook) Runs eslint
npm run docs Generates API.md from JSDoc comments in /src
npm run security-scan (Run as a git pre-push hook) Checks npm dependencies for security vulnerabilities
npm run release <version> Generates a changelog, updates package version, tags and pushes via np. This should only be run on an up-to-date master by a maintainer of this package.

Version can be a semver level: `patch

npm run will list all npm scripts

About

Boilerplate for a NPM package for the node and browser using ES2015

License:MIT License


Languages

Language:JavaScript 100.0%