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

Commit 577938d

Browse files
committed
⭐ new(build): support es module building
Closes #10
1 parent 0593890 commit 577938d

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

template/config/entry.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ const entries = {
2121
format: 'cjs',
2222
banner
2323
},
24+
esm: {
25+
entry: 'src/index.js',
26+
dest: `dist/${pack.name}.esm.js`,
27+
format: 'es',
28+
banner
29+
},
2430
production: {
2531
entry: 'src/index.js',
2632
dest: `dist/${pack.name}.min.js`,
@@ -52,12 +58,11 @@ function genConfig (opts) {
5258
]
5359
}
5460

61+
const replacePluginOptions = { '__VERSION__': pack.version }
5562
if (opts.env) {
56-
config.plugins.push(replace({
57-
'process.env.NODE_ENV': JSON.stringify(opts.env),
58-
'__VERSION__': pack.version
59-
}))
63+
replacePluginOptions['process.env.NODE_ENV'] = JSON.stringify(opts.env)
6064
}
65+
config.plugins.push(replace(replacePluginOptions))
6166

6267
return config
6368
}

template/dist/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1-
# NOTE!
1+
## Explanation of Build Files
22

3-
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.
3+
- UMD: {{ name }}.js
4+
- CommonJS: {{ name }}.common.js
5+
- ES Module: {{ name }}.esm.js
6+
7+
### Terms
8+
9+
- **[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`).
10+
11+
- **[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`).
12+
13+
- **[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`).

template/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,15 @@
8585
{{#unless_eq githubAccount ""}}
8686
"homepage": "https://github.com/{{ githubAccount }}/{{ name }}#readme",
8787
{{/unless_eq}}
88+
"main": "dist/{{ name }}.common.js",
89+
"module": "dist/{{ name }}.esm.js",
8890
"unpkg": "dist/{{ name }}.js",
8991
"keywords": [
9092
"plugin",
9193
"vue",
9294
"vuejs"
9395
],
9496
"license": "MIT",
95-
"main": "dist/{{ name }}.common.js",
9697
"engines": {
9798
"node": ">= 6.0"
9899
},

0 commit comments

Comments
 (0)