From 627027fd4351c1a6fa4926765c805165a56d7818 Mon Sep 17 00:00:00 2001 From: ziga Date: Wed, 10 Apr 2019 21:49:12 -0400 Subject: [PATCH] feat(esm build): build ES modules for browser (#2705) --- build/build.js | 18 ++++++++++-------- build/configs.js | 19 +++++++++++++++++-- package.json | 2 +- yarn.lock | 4 ++-- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/build/build.js b/build/build.js index fe374587c..09767b9e6 100644 --- a/build/build.js +++ b/build/build.js @@ -1,7 +1,7 @@ const fs = require('fs') const path = require('path') const zlib = require('zlib') -const uglify = require('uglify-js') +const terser = require('terser') const rollup = require('rollup') const configs = require('./configs') @@ -27,22 +27,24 @@ function build (builds) { } function buildEntry ({ input, output }) { - const isProd = /min\.js$/.test(output.file) + const { file, banner } = output + const isProd = /min\.js$/.test(file) return rollup.rollup(input) .then(bundle => bundle.generate(output)) .then(({ code }) => { if (isProd) { - const minified = uglify.minify(code, { + const minified = (banner ? banner + '\n' : '') + terser.minify(code, { + toplevel: true, output: { - preamble: output.banner, - /* eslint-disable camelcase */ ascii_only: true - /* eslint-enable camelcase */ + }, + compress: { + pure_funcs: ['makeMap'] } }).code - return write(output.file, minified, true) + return write(file, minified, true) } else { - return write(output.file, code) + return write(file, code) } }) } diff --git a/build/configs.js b/build/configs.js index f81ec3a93..67371b8e2 100644 --- a/build/configs.js +++ b/build/configs.js @@ -33,6 +33,18 @@ module.exports = [ { file: resolve('dist/vue-router.esm.js'), format: 'es' + }, + { + file: resolve('dist/vue-router.esm.browser.js'), + format: 'es', + env: 'development', + transpile: false + }, + { + file: resolve('dist/vue-router.esm.browser.min.js'), + format: 'es', + env: 'production', + transpile: false } ].map(genConfig) @@ -46,8 +58,7 @@ function genConfig (opts) { cjs(), replace({ __VERSION__: version - }), - buble() + }) ] }, output: { @@ -64,5 +75,9 @@ function genConfig (opts) { })) } + if (opts.transpile !== false) { + config.input.plugins.push(buble()) + } + return config } diff --git a/package.json b/package.json index 635a78823..525f8e6d1 100644 --- a/package.json +++ b/package.json @@ -82,8 +82,8 @@ "rollup-plugin-replace": "^2.0.0", "rollup-watch": "^4.0.0", "selenium-server": "^2.53.1", + "terser": "^3.17.0", "typescript": "^3.3.1", - "uglify-js": "^3.3.13", "vue": "^2.5.16", "vue-loader": "^15.2.1", "vue-template-compiler": "^2.5.16", diff --git a/yarn.lock b/yarn.lock index 27f99a012..897c945cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9828,7 +9828,7 @@ terser-webpack-plugin@^1.1.0: webpack-sources "^1.1.0" worker-farm "^1.5.2" -terser@^3.16.1: +terser@^3.16.1, terser@^3.17.0: version "3.17.0" resolved "https://registry.yarnpkg.com/terser/-/terser-3.17.0.tgz#f88ffbeda0deb5637f9d24b0da66f4e15ab10cb2" integrity sha512-/FQzzPJmCpjAH9Xvk2paiWrFq+5M6aVOf+2KRbwhByISDX/EujxsK+BAvrhb6H+2rtrLCHK9N01wO014vrIwVQ== @@ -10078,7 +10078,7 @@ uglify-js@3.4.x: commander "~2.19.0" source-map "~0.6.1" -uglify-js@^3.1.4, uglify-js@^3.3.13: +uglify-js@^3.1.4: version "3.4.9" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.9.tgz#af02f180c1207d76432e473ed24a28f4a782bae3" integrity sha512-8CJsbKOtEbnJsTyv6LE6m6ZKniqMiFWmm9sRbopbkGs3gMPPfd3Fh8iIA4Ykv5MgaTbqHr4BaoGLJLZNhsrW1Q==