Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
⭐ new(build): support es module building
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
kazupon committed Mar 23, 2017
1 parent 0593890 commit 577938d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
13 changes: 9 additions & 4 deletions template/config/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const entries = {
format: 'cjs',
banner
},
esm: {
entry: 'src/index.js',
dest: `dist/${pack.name}.esm.js`,
format: 'es',
banner
},
production: {
entry: 'src/index.js',
dest: `dist/${pack.name}.min.js`,
Expand Down Expand Up @@ -52,12 +58,11 @@ function genConfig (opts) {
]
}

const replacePluginOptions = { '__VERSION__': pack.version }
if (opts.env) {
config.plugins.push(replace({
'process.env.NODE_ENV': JSON.stringify(opts.env),
'__VERSION__': pack.version
}))
replacePluginOptions['process.env.NODE_ENV'] = JSON.stringify(opts.env)
}
config.plugins.push(replace(replacePluginOptions))

return config
}
Expand Down
14 changes: 12 additions & 2 deletions template/dist/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# NOTE!
## Explanation of Build Files

The `dist` folder contains the standalone build for {{ name }}, however files here are only checked-in when a release happens. If you are on the `{{ branch }}` branch, files here are **NOT** up to date. Only the `master` branch contains the built files for the latest stable version.
- UMD: {{ name }}.js
- CommonJS: {{ name }}.common.js
- ES Module: {{ name }}.esm.js

### Terms

- **[UMD](https://github.com/umdjs/umd)**: UMD builds can be used directly in the browser via a `<script>` tag. The default file from Unpkg CDN at [https://unpkg.com/{{ name }}](https://unpkg.com/{{ name }}) is the UMD build (`{{ name }}.js`).

- **[CommonJS](http://wiki.commonjs.org/wiki/Modules/1.1)**: CommonJS builds are intended for use with older bundlers like [browserify](http://browserify.org/) or [webpack 1](https://webpack.github.io). The default file for these bundlers (`pkg.main`) is the Runtime only CommonJS build (`{{ name }}.common.js`).

- **[ES Module](http://exploringjs.com/es6/ch_modules.html)**: ES module builds are intended for use with modern bundlers like [webpack 2](https://webpack.js.org) or [rollup](http://rollupjs.org/). The default file for these bundlers (`pkg.module`) is the Runtime only ES Module build (`{{ name }}.esm.js`).
3 changes: 2 additions & 1 deletion template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@
{{#unless_eq githubAccount ""}}
"homepage": "https://github.com/{{ githubAccount }}/{{ name }}#readme",
{{/unless_eq}}
"main": "dist/{{ name }}.common.js",
"module": "dist/{{ name }}.esm.js",
"unpkg": "dist/{{ name }}.js",
"keywords": [
"plugin",
"vue",
"vuejs"
],
"license": "MIT",
"main": "dist/{{ name }}.common.js",
"engines": {
"node": ">= 6.0"
},
Expand Down

0 comments on commit 577938d

Please sign in to comment.