Skip to content

feat: add browser ESM 'minified build' using babel-minify #8683

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

Closed
wants to merge 2 commits into from
Closed
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
32 changes: 24 additions & 8 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path')
const zlib = require('zlib')
const rollup = require('rollup')
const uglify = require('uglify-js')
const babel = require('babel-core')

if (!fs.existsSync('dist')) {
fs.mkdirSync('dist')
Expand Down Expand Up @@ -40,6 +41,28 @@ function build (builds) {
next()
}

function minify (code, minifier) {
if (minifier === 'uglify') {
return uglify.minify(code, {
output: {
ascii_only: true
},
compress: {
pure_funcs: ['makeMap']
}
}).code
} else if (minifier === 'babel') {
return babel.transform(code, {
babelrc: false,
presets: [['minify', {
mangle: { topLevel: true }
}]]
}).code
} else {
return code
}
}

function buildEntry (config) {
const output = config.output
const { file, banner } = output
Expand All @@ -48,14 +71,7 @@ function buildEntry (config) {
.then(bundle => bundle.generate(output))
.then(({ code }) => {
if (isProd) {
var minified = (banner ? banner + '\n' : '') + uglify.minify(code, {
output: {
ascii_only: true
},
compress: {
pure_funcs: ['makeMap']
}
}).code
var minified = (banner ? banner + '\n' : '') + minify(code, config._minifier || 'uglify')
return write(file, minified, true)
} else {
return write(file, code)
Expand Down
20 changes: 18 additions & 2 deletions build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ const builds = {
alias: { he: './entity-decoder' },
banner
},
// Runtime+compiler ES modules build (for direct import in browser)
'web-full-esm-browser': {
// Runtime+compiler ES modules development build (for direct import in browser)
'web-full-esm-browser-dev': {
entry: resolve('web/entry-runtime-with-compiler.js'),
dest: resolve('dist/vue.esm.browser.js'),
format: 'es',
Expand All @@ -76,6 +76,17 @@ const builds = {
alias: { he: './entity-decoder' },
banner
},
// Runtime+compiler ES modules production build (for direct import in browser)
'web-full-esm-browser-prod': {
entry: resolve('web/entry-runtime-with-compiler.js'),
dest: resolve('dist/vue.esm.browser.min.js'),
format: 'es',
transpile: false,
minifier: 'babel',
env: 'production',
alias: { he: './entity-decoder' },
banner
},
// runtime-only build (Browser)
'web-runtime-dev': {
entry: resolve('web/entry-runtime.js'),
Expand Down Expand Up @@ -215,6 +226,11 @@ function genConfig (name) {
value: name
})

Object.defineProperty(config, '_minifier', {
enumerable: false,
value: opts.minifier
})

return config
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"babel-preset-flow-vue": "^1.0.0",
"buble": "^0.16.0",
"chalk": "^1.1.3",
"babel-preset-minify": "^0.4.3",
"chromedriver": "^2.30.1",
"codecov.io": "^0.1.6",
"commitizen": "^2.9.6",
Expand Down