diff --git a/config/bundle.js b/config/bundle.js index 098b97c02..eecd3d51c 100644 --- a/config/bundle.js +++ b/config/bundle.js @@ -2,7 +2,7 @@ const fs = require('fs') const path = require('path') const zlib = require('zlib') const rollup = require('rollup') -const uglify = require('uglify-js') +const terser = require('terser') module.exports = build @@ -28,8 +28,8 @@ function buildEntry (config) { .then(bundle => bundle.generate(output)) .then(({ code }) => { if (isProd) { - var minified = (banner ? banner + '\n' : '') + uglify.minify(code, { - fromString: true, + var minified = (banner ? banner + '\n' : '') + terser.minify(code, { + toplevel: true, output: { ascii_only: true }, diff --git a/config/entry.js b/config/entry.js index ef8d53a3d..491025df6 100644 --- a/config/entry.js +++ b/config/entry.js @@ -46,6 +46,22 @@ const entries = { env: 'development', moduleName, banner + }, + browser_development: { + entry: 'src/index.js', + dest: resolve(`dist/${pack.name}.esm.browser.js`), + format: 'es', + env: 'development', + moduleName, + transpile: false + }, + browser_production: { + entry: 'src/index.js', + dest: resolve(`dist/${pack.name}.esm.browser.min.js`), + format: 'es', + env: 'production', + moduleName, + transpile: false } } @@ -61,8 +77,7 @@ function genConfig (opts) { plugins: [ flow(), node(), - cjs(), - buble() + cjs() ] } @@ -72,6 +87,10 @@ function genConfig (opts) { } config.plugins.push(replace(replacePluginOptions)) + if (opts.transpile !== false) { + config.plugins.push(buble()) + } + return config } diff --git a/dist/README.md b/dist/README.md index 5d840c96d..61415961b 100644 --- a/dist/README.md +++ b/dist/README.md @@ -1,8 +1,9 @@ -## Explanation of Build Files +## Explanation of Different Builds -- UMD: vue-i18n.js -- CommonJS: vue-i18n.common.js -- ES Module: vue-i18n.esm.js +- UMD: `vue-i18n.js` +- CommonJS: `vue-i18n.common.js` +- ES Module for bundlers: `vue-i18n.esm.js` +- ES Module for browsers: `vue-i18n.esm.browser.js` ### Terms @@ -10,4 +11,6 @@ - **[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 (`vue-i18n.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 (`vue-i18n.esm.js`). +- **[ES Module](http://exploringjs.com/es6/ch_modules.html)**: starting in 8.11 VueI18n provides two ES Modules (ESM) builds: + - ESM for bundlers: intended for use with modern bundlers like [webpack 2](https://webpack.js.org) or [Rollup](https://rollupjs.org/). ESM format is designed to be statically analyzable so the bundlers can take advantage of that to perform "tree-shaking" and eliminate unused code from your final bundle. The default file for these bundlers (`pkg.module`) is the Runtime only ES Module build (`vue-i18n.esm.js`). + - ESM for browsers (8.11+ only, `vue-i18n.esm.browser.js`): intended for direct imports in modern browsers via `