Skip to content

Repository files navigation

js-library-boilerplate

Rollup based javascript library boilerplate featuring Babel 7, ESLint, flow, jest, JSDoc, Rollup, semantic-release and live debugginga.

Commitizen friendly coverage statements coverage lines coverage functions semantic-release

js-library-boilerplate logo

Getting Started:

This boilerplate including a basic code to start creating a js based library.

Start with cloning the project:

$ git clone --depth=1 git://github.com/wadehrarshpreet/js-library-boilerplate.git your-project-name
  • Remove the .git directory (rm -rf your-project-name/.git).
  • Edit package.json and change the name of the project to your project name.
  • The boilerplate without any changes supporting creating a library for both CommonJS, es6 modules, amd and browser.

Now, create a new github project and do:

$ git init
$ git remote add origin https://github.com/your-name/your-project-name.git
$ git add -A
$ npm run commit
$ git push origin master

This project is using semantic-release to automatic handling of the version of your library. To be able to automatic release a new version you must configure Travis-CI to your new project:

  • Go to https://travis-ci.org/ and either signup or signin.
  • Select your new project and click setting.
  • You MUST configure a token or semantic-release will not be able to commit changes:
    • Create a new token (see here how to do it).
    • Permissions needed in the github token:
      • repo:
        • repo:status
        • repo_deployment
        • public_repo
      • admin:org:
        • read:org
      • admin:repo_hook:
        • write:repo_hook
      • user:
        • user:email
    • In your Travis-CI project setting, go to the environment settings section and add a new environment variable with the name 'GH_TOKEN' and the generated token as the data.
  • To test everything just push something into github and it should update everything automatic!

Allow doing npm publish automatically by semantic-release:

  • You need a npm token (see here) and add it as the NPM_TOKEN environment variable to Travis-CI like you did with the GH_TOKEN for github.
  • Update the release section in package.json and add '@semantic-release/npm' to both 'prepare', 'publish' and 'verifyConditions'.

External dependencies:

This project is using the following awesome libraries/utilities/services:

Installation:

via yarn:

$ yarn add your-library

via npm:

$ npm install your-library

Documentation:

To generate the library documentation using jsdocs:

$ yarn doc

or:

$ npm run doc

☕ The source code:

The project structure:

- your-library/lib/ - All the sources should be here.
- your-library/lib/types/ - All the flow type declarations.
- your-library/__tests__/ - All the unit tests.
- your-library/build-tool/rollup.config.js - The configuration for [rollup](https://rollupjs.org/).
- your-library/build-tool/build.js - Script to generate build ES, CJS(using babel), UMD, IIFE, AMD(using rollup). 
- .editorconfig - The [coding style settings](https://editorconfig.org/) for this project.
- .prettierrc - Prettier configuration for this project.

Npm scripts:

When using with yarn then use the following syntax:

$ yarn name params

Or with just npm:

$ npm name params
  • start - Run the code in development mode.
  • build - Build the production mode.
  • lint - Lint 👮 using ESLint.
  • flow - Flow checks.
  • test - Run tests using jest
  • dev - Build development builds(no minify)
  • dev:watch - watch dev build (no minify)
  • commit - using commitzen wizard to make commit
  • release - Using semantic-release to create new release

About

Boilerplate for JS Library (export your build multiple format CJS, ESM, UMD, AMD, IIFE)

Topics

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages