Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(esm build): build ES modules for browser #2705

Merged
merged 3 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions build/build.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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)
}
})
}
Expand Down
19 changes: 17 additions & 2 deletions build/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -46,8 +58,7 @@ function genConfig (opts) {
cjs(),
replace({
__VERSION__: version
}),
buble()
})
]
},
output: {
Expand All @@ -64,5 +75,9 @@ function genConfig (opts) {
}))
}

if (opts.transpile !== false) {
config.input.plugins.push(buble())
}

return config
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand Down