Skip to content

Commit 4555d82

Browse files
committed
feat: use rollup to build component
1 parent 6e35dfa commit 4555d82

13 files changed

Lines changed: 665 additions & 49 deletions

File tree

.babelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
]
77
],
88
"plugins": [
9-
"transform-runtime",
10-
"transform-vue-jsx"
9+
"transform-vue-jsx",
10+
"external-helpers"
1111
]
1212
}

build/rollup.component.config.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import path from 'path';
2+
import vue from 'rollup-plugin-vue';
3+
import alias from 'zan-rollup-plugin-alias';
4+
import babel from 'rollup-plugin-babel';
5+
import resolve from 'rollup-plugin-node-resolve';
6+
import commonjs from 'rollup-plugin-commonjs';
7+
import componentsConfig from '../components.json';
8+
9+
const extensions = ['.js', '.vue'];
10+
11+
export default Object.keys(componentsConfig).map(component => {
12+
return {
13+
entry: componentsConfig[component],
14+
targets: [
15+
{
16+
dest: path.resolve(__dirname, `../lib/${component}/index.js`),
17+
format: 'cjs'
18+
}
19+
],
20+
external: ['vue', 'vue-lazyload'],
21+
plugins: [
22+
vue(),
23+
babel({
24+
externalHelpers: true
25+
}),
26+
resolve({
27+
main: true,
28+
jsnext: true,
29+
extensions
30+
}),
31+
commonjs({
32+
extensions
33+
}),
34+
alias({
35+
resolve: extensions,
36+
'src/mixins': path.resolve(__dirname, '../packages/common/mixins'),
37+
'src/utils': path.resolve(__dirname, '../packages/common/utils'),
38+
packages: path.resolve(__dirname, '../packages')
39+
}),
40+
]
41+
};
42+
});

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"packages"
1212
],
1313
"scripts": {
14-
"bootstrap": "yarn || npm i",
14+
"bootstrap": "yarn || npm i && cd ./packages/vant-css/ && yarn || npm i && cd ../../",
1515
"dev": "npm run build:file && webpack-dev-server --inline --config build/webpack.config.dev.js --content-base ./",
1616
"build:file": "node build/bin/build-entry.js",
1717
"build:utils": "cross-env BABEL_ENV=utils babel src --out-dir lib --ignore src/index.js --presets=es2015",
@@ -27,7 +27,8 @@
2727
"test": "karma start test/unit/karma.conf.js --single-run",
2828
"test:coverage": "open test/unit/coverage/lcov-report/index.html",
2929
"test:watch": "karma start test/unit/karma.conf.js",
30-
"release": "npm run bootstrap && sh build/release.sh"
30+
"release": "npm run bootstrap && sh build/release.sh",
31+
"rollup": "rollup -c ./build/rollup.component.config.js"
3132
},
3233
"repository": {
3334
"type": "git",
@@ -53,13 +54,15 @@
5354
"babel-cli": "^6.14.0",
5455
"babel-core": "^6.25.0",
5556
"babel-loader": "^7.1.1",
57+
"babel-plugin-external-helpers": "^6.22.0",
5658
"babel-plugin-module-resolver": "^2.7.1",
5759
"babel-plugin-syntax-jsx": "^6.18.0",
5860
"babel-plugin-transform-runtime": "^6.15.0",
5961
"babel-plugin-transform-vue-jsx": "^3.5.0",
6062
"babel-polyfill": "^6.23.0",
6163
"babel-preset-es2015": "^6.16.0",
6264
"babel-runtime": "^6.25.0",
65+
"babelrc-rollup": "^3.0.0",
6366
"chai": "^4.1.1",
6467
"cheerio": "^0.22.0",
6568
"codecov": "^2.2.0",
@@ -97,6 +100,11 @@
97100
"precss": "^2.0.0",
98101
"progress-bar-webpack-plugin": "^1.10.0",
99102
"rimraf": "^2.5.4",
103+
"rollup": "^0.45.2",
104+
"rollup-plugin-babel": "^3.0.1",
105+
"rollup-plugin-commonjs": "^8.1.0",
106+
"rollup-plugin-node-resolve": "^3.0.0",
107+
"rollup-plugin-vue": "^2.4.1",
100108
"run-sequence": "^2.1.0",
101109
"sinon": "^2.4.1",
102110
"sinon-chai": "^2.12.0",
@@ -115,6 +123,7 @@
115123
"webpack": "^3.5.1",
116124
"webpack-dev-server": "^2.7.1",
117125
"webpack-merge": "^4.1.0",
118-
"zan-doc": "0.1.12"
126+
"zan-doc": "0.1.12",
127+
"zan-rollup-plugin-alias": "1.0.1"
119128
}
120129
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import merge from 'src/utils/merge';
1+
import merge from '../../utils/merge';
22
import PopupManager from './popup-manager';
33
import PopupContext from './popup-context';
44

src/mixins/popup/popup-context.js renamed to packages/common/mixins/popup/popup-context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import merge from 'src/utils/merge';
1+
import merge from '../../utils/merge';
22
import Vue from 'vue';
33

44
let context;

src/mixins/popup/popup-manager.js renamed to packages/common/mixins/popup/popup-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Vue from 'vue';
2-
import { addClass } from 'src/utils/dom';
2+
import { addClass } from '../../utils/dom';
33
import PopupContext from './popup-context';
44

55
const getModal = function() {

0 commit comments

Comments
 (0)