Skip to content

Commit 6f41fa4

Browse files
author
zhaozhiwen
committed
feat(build): 打包commonjs模块
1 parent 2066f40 commit 6f41fa4

File tree

6 files changed

+932
-30
lines changed

6 files changed

+932
-30
lines changed

.babelrc.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
presets: ['@babel/env', '@babel/typescript', '@babel/react'],
3+
plugins: [
4+
'@babel/proposal-class-properties',
5+
[
6+
'@babel/plugin-transform-runtime',
7+
{
8+
corejs: 3,
9+
helpers: true,
10+
},
11+
],
12+
],
13+
};

.browserslistrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
>0.2%
2+
not dead
3+
not op_mini all

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/build
1616
/dist
1717
/lib
18-
/es
18+
/esm
1919
/.docz
2020
/doc-site
2121
/types

gulpfile.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const gulp = require('gulp');
2+
const babel = require('gulp-babel');
3+
4+
const paths = {
5+
dest: {
6+
lib: 'lib',
7+
esm: 'esm',
8+
dist: 'dist',
9+
},
10+
styles: 'components/**/*.less',
11+
scripts: ['components/**/*.{ts,tsx}', '!components/**/demo/*.{ts,tsx}'],
12+
};
13+
14+
function compileCJS() {
15+
const { dest, scripts } = paths;
16+
return gulp
17+
.src(scripts)
18+
.pipe(babel()) // 使用gulp-babel处理
19+
.pipe(gulp.dest(dest.lib));
20+
}
21+
22+
const build = gulp.parallel(compileCJS);
23+
24+
exports.build = build;
25+
26+
exports.default = build;

package.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
"name": "react-ui-library-tutorial",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "index.js",
65
"typings": "types/index.d.ts",
6+
"main": "lib/index.js",
77
"scripts": {
88
"dev": "docz dev",
99
"start": "npm run dev",
1010
"build:doc": "rimraf doc-site && docz build",
1111
"preview:doc": "docz serve",
12+
"clean": "rimraf types lib esm dist",
1213
"build:types": "tsc --emitDeclarationOnly",
14+
"build": "npm run clean && npm run build:types && gulp",
1315
"commit": "git-cz",
1416
"test": "echo \"Error: no test specified\" && exit 1"
1517
},
@@ -29,6 +31,13 @@
2931
"react-dom": ">=16.0.0"
3032
},
3133
"devDependencies": {
34+
"@babel/core": "^7.7.7",
35+
"@babel/plugin-proposal-class-properties": "^7.7.4",
36+
"@babel/plugin-proposal-object-rest-spread": "^7.7.7",
37+
"@babel/plugin-transform-runtime": "^7.7.6",
38+
"@babel/preset-env": "^7.7.7",
39+
"@babel/preset-react": "^7.7.4",
40+
"@babel/preset-typescript": "^7.7.7",
3241
"@commitlint/cli": "^8.2.0",
3342
"@commitlint/config-conventional": "^8.2.0",
3443
"@types/vfile-message": "^2.0.0",
@@ -40,6 +49,8 @@
4049
"docz": "^2.2.0",
4150
"gatsby-plugin-import": "^2.1.5",
4251
"gatsby-plugin-less": "^3.0.17",
52+
"gulp": "^4.0.2",
53+
"gulp-babel": "^8.0.0",
4354
"husky": "^3.1.0",
4455
"less": "^3.10.3",
4556
"lint-staged": "^9.5.0",
@@ -77,6 +88,7 @@
7788
}
7889
},
7990
"dependencies": {
91+
"@babel/runtime-corejs3": "^7.7.7",
8092
"prop-types": "^15.7.2"
8193
}
8294
}

0 commit comments

Comments
 (0)