Skip to content

Commit

Permalink
feat(build): 打包commonjs模块
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaozhiwen committed Dec 24, 2019
1 parent 2066f40 commit 6f41fa4
Show file tree
Hide file tree
Showing 6 changed files with 932 additions and 30 deletions.
13 changes: 13 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
presets: ['@babel/env', '@babel/typescript', '@babel/react'],
plugins: [
'@babel/proposal-class-properties',
[
'@babel/plugin-transform-runtime',
{
corejs: 3,
helpers: true,
},
],
],
};
3 changes: 3 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
>0.2%
not dead
not op_mini all
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/build
/dist
/lib
/es
/esm
/.docz
/doc-site
/types
Expand Down
26 changes: 26 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const gulp = require('gulp');
const babel = require('gulp-babel');

const paths = {
dest: {
lib: 'lib',
esm: 'esm',
dist: 'dist',
},
styles: 'components/**/*.less',
scripts: ['components/**/*.{ts,tsx}', '!components/**/demo/*.{ts,tsx}'],
};

function compileCJS() {
const { dest, scripts } = paths;
return gulp
.src(scripts)
.pipe(babel()) // 使用gulp-babel处理
.pipe(gulp.dest(dest.lib));
}

const build = gulp.parallel(compileCJS);

exports.build = build;

exports.default = build;
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"name": "react-ui-library-tutorial",
"version": "1.0.0",
"description": "",
"main": "index.js",
"typings": "types/index.d.ts",
"main": "lib/index.js",
"scripts": {
"dev": "docz dev",
"start": "npm run dev",
"build:doc": "rimraf doc-site && docz build",
"preview:doc": "docz serve",
"clean": "rimraf types lib esm dist",
"build:types": "tsc --emitDeclarationOnly",
"build": "npm run clean && npm run build:types && gulp",
"commit": "git-cz",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -29,6 +31,13 @@
"react-dom": ">=16.0.0"
},
"devDependencies": {
"@babel/core": "^7.7.7",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-proposal-object-rest-spread": "^7.7.7",
"@babel/plugin-transform-runtime": "^7.7.6",
"@babel/preset-env": "^7.7.7",
"@babel/preset-react": "^7.7.4",
"@babel/preset-typescript": "^7.7.7",
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"@types/vfile-message": "^2.0.0",
Expand All @@ -40,6 +49,8 @@
"docz": "^2.2.0",
"gatsby-plugin-import": "^2.1.5",
"gatsby-plugin-less": "^3.0.17",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"husky": "^3.1.0",
"less": "^3.10.3",
"lint-staged": "^9.5.0",
Expand Down Expand Up @@ -77,6 +88,7 @@
}
},
"dependencies": {
"@babel/runtime-corejs3": "^7.7.7",
"prop-types": "^15.7.2"
}
}
Loading

0 comments on commit 6f41fa4

Please sign in to comment.