Skip to content

Commit d98ea64

Browse files
authored
build: update the build system to the latest structure (vuejs#1729)
* build: update the build system to the latest structure * build: use __DEV__ global * chore: ignore all `node_modules` folder * build: tweek some bundle settings
1 parent 0759774 commit d98ea64

28 files changed

+511
-410
lines changed

.eslintrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"root": true,
33
"extends": [
44
"plugin:vue-libs/recommended"
5-
]
5+
],
6+
"globals": {
7+
"__DEV__": true
8+
}
69
}

.gitignore

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1+
/docs/.vuepress/dist
2+
/examples/**/build.js
3+
/test/e2e/reports
4+
/test/e2e/screenshots
5+
/types/typings
6+
/types/test/*.js
7+
*.log
18
.DS_Store
29
node_modules
3-
TODO.md
4-
lib
5-
docs/.vuepress/dist
6-
examples/**/build.js
7-
types/typings
8-
types/test/*.js
9-
explorations
10-
*.log
11-
test/e2e/reports
12-
test/e2e/screenshots

build/build.main.js

-83
This file was deleted.

build/configs.js

-92
This file was deleted.

build/rollup.dev.config.js

-3
This file was deleted.

build/rollup.logger.config.js

-11
This file was deleted.

examples/webpack.config.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = {
3333

3434
resolve: {
3535
alias: {
36-
vuex: path.resolve(__dirname, '../src/index.esm.js')
36+
vuex: path.resolve(__dirname, '../src/index.js')
3737
}
3838
},
3939

@@ -52,6 +52,12 @@ module.exports = {
5252
plugins: [
5353
new VueLoaderPlugin(),
5454
new webpack.HotModuleReplacementPlugin(),
55-
new webpack.NoEmitOnErrorsPlugin()
55+
new webpack.NoEmitOnErrorsPlugin(),
56+
new webpack.DefinePlugin({
57+
__DEV__: JSON.stringify(true),
58+
'process.env': {
59+
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
60+
}
61+
})
5662
]
5763
}

package.json

+17-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"unpkg": "dist/vuex.js",
88
"jsdelivr": "dist/vuex.js",
99
"typings": "types/index.d.ts",
10+
"sideEffects": false,
1011
"files": [
1112
"dist",
1213
"types/index.d.ts",
@@ -15,18 +16,17 @@
1516
],
1617
"scripts": {
1718
"dev": "node examples/server.js",
18-
"dev:dist": "rollup -wm -c build/rollup.dev.config.js",
1919
"build": "npm run build:main && npm run build:logger",
20-
"build:main": "node build/build.main.js",
21-
"build:logger": "rollup -c build/rollup.logger.config.js",
20+
"build:main": "node scripts/build-main.js",
21+
"build:logger": "node scripts/build-logger.js",
2222
"lint": "eslint src test",
2323
"test": "npm run lint && npm run test:types && npm run test:unit && npm run test:ssr && npm run test:e2e",
24-
"test:unit": "rollup -c build/rollup.dev.config.js && jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
24+
"test:unit": "jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
2525
"test:e2e": "node test/e2e/runner.js",
26-
"test:ssr": "rollup -c build/rollup.dev.config.js && cross-env VUE_ENV=server jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
26+
"test:ssr": "cross-env VUE_ENV=server jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
2727
"test:types": "tsc -p types/test",
2828
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
29-
"release": "bash build/release.sh",
29+
"release": "bash scripts/release.sh",
3030
"docs": "vuepress dev docs",
3131
"docs:build": "vuepress build docs"
3232
},
@@ -44,29 +44,35 @@
4444
"vue": "^2.0.0"
4545
},
4646
"devDependencies": {
47+
"@rollup/plugin-buble": "^0.21.3",
48+
"@rollup/plugin-commonjs": "^11.1.0",
49+
"@rollup/plugin-node-resolve": "^7.1.3",
50+
"@rollup/plugin-replace": "^2.3.2",
51+
"@types/node": "^13.13.2",
4752
"babel-core": "^6.22.1",
4853
"babel-loader": "^7.1.2",
4954
"babel-plugin-transform-object-rest-spread": "^6.23.0",
5055
"babel-polyfill": "^6.22.0",
5156
"babel-preset-env": "^1.5.1",
57+
"brotli": "^1.3.2",
58+
"chalk": "^4.0.0",
5259
"chromedriver": "^80.0.1",
5360
"conventional-changelog-cli": "^2.0.31",
5461
"cross-env": "^5.2.0",
5562
"cross-spawn": "^6.0.5",
5663
"css-loader": "^2.1.0",
5764
"eslint": "^6.8.0",
5865
"eslint-plugin-vue-libs": "^4.0.0",
66+
"execa": "^4.0.0",
5967
"express": "^4.17.1",
6068
"jasmine": "2.8.0",
6169
"jasmine-core": "2.8.0",
6270
"nightwatch": "^1.3.1",
6371
"nightwatch-helpers": "^1.2.0",
64-
"rollup": "^1.1.0",
65-
"rollup-plugin-buble": "^0.19.6",
66-
"rollup-plugin-replace": "^2.1.0",
67-
"terser": "^3.17.0",
72+
"rollup": "^2.7.2",
73+
"rollup-plugin-terser": "^5.3.0",
6874
"todomvc-app-css": "^2.1.0",
69-
"typescript": "^3.7.2",
75+
"typescript": "^3.8.3",
7076
"vue": "^2.5.22",
7177
"vue-loader": "^15.2.1",
7278
"vue-template-compiler": "^2.5.22",

rollup.config.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import buble from '@rollup/plugin-buble'
2+
import replace from '@rollup/plugin-replace'
3+
import resolve from '@rollup/plugin-node-resolve'
4+
import commonjs from '@rollup/plugin-commonjs'
5+
import { terser } from 'rollup-plugin-terser'
6+
import pkg from './package.json'
7+
8+
const banner = `/*!
9+
* vuex v${pkg.version}
10+
* (c) ${new Date().getFullYear()} Evan You
11+
* @license MIT
12+
*/`
13+
14+
export function createEntries(configs) {
15+
return configs.map((c) => createEntry(c))
16+
}
17+
18+
function createEntry(config) {
19+
const c = {
20+
input: config.input,
21+
plugins: [],
22+
output: {
23+
banner,
24+
file: config.file,
25+
format: config.format
26+
},
27+
onwarn: (msg, warn) => {
28+
if (!/Circular/.test(msg)) {
29+
warn(msg)
30+
}
31+
}
32+
}
33+
34+
if (config.format === 'umd') {
35+
c.output.name = c.output.name || 'Vuex'
36+
}
37+
38+
c.plugins.push(replace({
39+
__VERSION__: pkg.version,
40+
__DEV__: config.format !== 'umd' && !config.browser
41+
? `(process.env.NODE_ENV !== 'production')`
42+
: config.env !== 'production'
43+
}))
44+
45+
if (config.transpile !== false) {
46+
c.plugins.push(buble())
47+
}
48+
49+
c.plugins.push(resolve())
50+
c.plugins.push(commonjs())
51+
52+
if (config.minify) {
53+
c.plugins.push(terser({ module: config.format === 'es' }))
54+
}
55+
56+
return c
57+
}

rollup.logger.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createEntries } from './rollup.config'
2+
3+
export default createEntries([
4+
{ input: 'src/plugins/logger.js', file: 'dist/logger.js', name: 'createVuexLogger', format: 'umd', env: 'development' }
5+
])

rollup.main.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { createEntries } from './rollup.config'
2+
3+
export default createEntries([
4+
{ input: 'src/index.js', file: 'dist/vuex.esm.browser.js', format: 'es', browser: true, transpile: false, env: 'development' },
5+
{ input: 'src/index.js', file: 'dist/vuex.esm.browser.min.js', format: 'es', browser: true, transpile: false, minify: true, env: 'production' },
6+
{ input: 'src/index.js', file: 'dist/vuex.esm.js', format: 'es', env: 'development' },
7+
{ input: 'src/index.cjs.js', file: 'dist/vuex.js', format: 'umd', env: 'development' },
8+
{ input: 'src/index.cjs.js', file: 'dist/vuex.min.js', format: 'umd', minify: true, env: 'production' },
9+
{ input: 'src/index.cjs.js', file: 'dist/vuex.common.js', format: 'cjs', env: 'development' }
10+
])

scripts/build-logger.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { run } = require('./build')
2+
3+
const files = ['dist/logger.js']
4+
5+
run('rollup.logger.config.js', files)

0 commit comments

Comments
 (0)