Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es6-npm-boilerplate

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-npm-boilerplate

Boilerplate for authoring in ES6 and publishing in ES5.

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

es6-npm-boilerplate

Boilerplate for authoring in ES6 and publishing in ES5. Includes unit tests with Jest which are themselves authored in ES6.

Why Publish in ES5?

The benefits of authoring in ES6 are self-evident. But as explained by Brian LeRoux in ES6 Modules: The End of Civilization As We Know It?, when publishing JavaScript code, there's no guarantee that your consumer will be using an ES6-supported environment. If you don't publish ES5 source, then, you're putting the onus on them to run your build step--and odds are, they won't be up for it.

To quote Brian:

The only realistic assumption is the target runtime will be ES5 compatible.

Functionality

Transpilation is handled by the 6to5 module. Specifically, the entire src directory is compiled into the dist directory, as outlined in the package.json's prepublish script:

6to5 --modules common src --out-dir dist"

As the prepublish script is run by default whenever you publish to npm, you (as the author) never have to worry about transpiling.

In addition, we point the package.json to dist/index.js (to make sure that require('es6-npm-boilerplate') loads the ES5 source) with this line:

{
  ...
  "main": "dist/index.js",
  ...
}

Unit Tests

Unit tests are configured to pass all source through __tests__/jest.conf.js, which again runs 6to5. The configuration file is kept in the __tests__ directory to reduce clutter. This preprocessing step is handled with this portion of the package.json:

{
  ...
  "jest": {
    "scriptPreprocessor": "__tests__/jest.conf.js",
    "testPathIgnorePatterns": [
      "/node_modules/",
      "./__tests__/jest.conf.js"
    ]
  },
  ...
}

The ability to author your tests in ES6 and run them without an additional build step makes for a pretty remarkable experience.

What Gets Published?

Only the dist directory, package.json, and README are published to npm, as these are the only relevant parts of the codebase in the eyes of a consumer. This behavior is enforced by the .npmignore file, which reads as follows:

__tests__
src

Even if you choose to include these directories, you should still add an empty .npmignore to your repository. Otherwise, npm will default to a .npmignore that includes dist and thus the compiled ES5 code won't be published.

Acknowledgements

Thanks to Brian LeRoux for his helpful article and talking over some of this with me.

License

CC0.

Keywords

FAQs

Package last updated on 23 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc