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 #1533

Merged
merged 1 commit 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
17 changes: 10 additions & 7 deletions build/build.main.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,21 +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(({ output: [{ code }] }) => {
if (isProd) {
var minified = (output.banner ? output.banner + '\n' : '') + uglify.minify(code, {
const minified = (banner ? banner + '\n' : '') + terser.minify(code, {
toplevel: true,
output: {
/* 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
21 changes: 19 additions & 2 deletions build/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ const configs = {
input: resolve('src/index.esm.js'),
file: resolve('dist/vuex.esm.js'),
format: 'es'
},
'esm-browser-dev': {
input: resolve('src/index.esm.js'),
file: resolve('dist/vuex.esm.browser.js'),
format: 'es',
env: 'development',
transpile: false
},
'esm-browser-prod': {
input: resolve('src/index.esm.js'),
file: resolve('dist/vuex.esm.browser.min.js'),
format: 'es',
env: 'production',
transpile: false
}
}

Expand All @@ -43,8 +57,7 @@ function genConfig (opts) {
plugins: [
replace({
__VERSION__: version
}),
buble()
})
]
},
output: {
Expand All @@ -61,6 +74,10 @@ function genConfig (opts) {
}))
}

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

return config
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
"rollup-plugin-buble": "^0.19.6",
"rollup-plugin-replace": "^2.1.0",
"selenium-server": "^2.53.1",
"terser": "^3.17.0",
"todomvc-app-css": "^2.1.0",
"typescript": "^3.2.2",
"uglify-js": "^3.1.2",
"vue": "^2.5.22",
"vue-loader": "^15.2.1",
"vue-template-compiler": "^2.5.22",
Expand Down
24 changes: 23 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2729,6 +2729,11 @@ commander@^2.15.1:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"
integrity sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==

commander@^2.19.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==

common-tags@^1.4.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/common-tags/-/common-tags-1.8.0.tgz#8e3153e542d4a39e9b10554434afaaf98956a937"
Expand Down Expand Up @@ -8406,6 +8411,14 @@ source-map-support@^0.4.15:
dependencies:
source-map "^0.5.6"

source-map-support@~0.5.10:
version "0.5.12"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.12.tgz#b4f3b10d51857a5af0138d3ce8003b201613d599"
integrity sha512-4h2Pbvyy15EE02G+JOZpUCmqWJuqrs+sEkzewTm++BPi7Hvn/HwcqLAcNxYAyI0x13CpPPn+kMjl+hplXMHITQ==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map-support@~0.5.6:
version "0.5.10"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.10.tgz#2214080bc9d51832511ee2bab96e3c2f9353120c"
Expand Down Expand Up @@ -8825,6 +8838,15 @@ terser-webpack-plugin@^1.1.0:
webpack-sources "^1.1.0"
worker-farm "^1.5.2"

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==
dependencies:
commander "^2.19.0"
source-map "~0.6.1"
source-map-support "~0.5.10"

terser@^3.8.1:
version "3.14.1"
resolved "https://registry.yarnpkg.com/terser/-/terser-3.14.1.tgz#cc4764014af570bc79c79742358bd46926018a32"
Expand Down Expand Up @@ -9057,7 +9079,7 @@ uc.micro@^1.0.1, uc.micro@^1.0.5:
resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.5.tgz#0c65f15f815aa08b560a61ce8b4db7ffc3f45376"
integrity sha512-JoLI4g5zv5qNyT09f4YAvEZIIV1oOjqnewYg5D38dkQljIzpPT296dbIGvKro3digYI1bkb7W6EP1y4uDlmzLg==

[email protected], uglify-js@^3.1.2:
[email protected]:
version "3.4.9"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.9.tgz#af02f180c1207d76432e473ed24a28f4a782bae3"
integrity sha512-8CJsbKOtEbnJsTyv6LE6m6ZKniqMiFWmm9sRbopbkGs3gMPPfd3Fh8iIA4Ykv5MgaTbqHr4BaoGLJLZNhsrW1Q==
Expand Down