Socket
Book a DemoInstallSign in
Socket

es6-esm-boilerplate

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-esm-boilerplate

Build ES modules from ES6 source code

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

es6-esm-boilerplate

Build ES modules from ES6 source code with Webpack.

Starting with this boilerplate, we can develop simple-to-complex ES Modules targeting the latest browsers, development with Babel, and Node runtime. At the same time, the ES5-compatible build is also generated.

Input/output structure

es6-esm-boilerplate
├── package.json
├── webpack.config.js
├── src                         # ES6 source code
│   ├── Base.js                 # class 
│   ├── Foo.js                  # subclass of Base
│   ├── Bar.js                  # subclass of Base
│   ├── index.js                # module implementation (export { Foo, Bar })
│
├── lib                         # ES module output
│   ├── my-module.js            # esm
│   ├── my-module.min.js        # esm minified
│   ├── my-module.compat.js     # esm with ES5-compatibility
│   ├── my-module.compat.min.js # esm with ES5-compatibility minified

How it works

ES6 source code          -> var-module             -> my-module.js (export default MyModule;)
{Base,Foo,Bar,index}.js     (var MyModule = ...;)  -> my-module.compat.js (UMD)

First, bundle ES6 source code into a var-module. Then, export the var-module using the ES Module's export syntax to finally get my-module.js. This module file can be directly consumed on relatively new browsers.

we also build my-module.compat.js for compatibility with older browsers, development with Babel, and NodeJS. This module file conforms to the UMD patterns that provide the script-tag loading, Node-require, and AMD compatibilities.

All the "var-to-esm transformation" is performed by a tiny Webpack plugin called webpack-var2esm-plugin.

Demo

Build

$ npm install  # set up build tools
$ npm run build  # get ES module output in lib/ by Babel

Keywords

es6

FAQs

Package last updated on 09 Oct 2018

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.