[new feature]: compile es5 dist

fix #1469
This commit is contained in:
rex 2019-04-03 10:16:15 +08:00 committed by GitHub
parent 17c84a5088
commit cded2c8a4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 25 deletions

View File

@ -6,16 +6,21 @@ const insert = require('gulp-insert');
const rename = require('gulp-rename'); const rename = require('gulp-rename');
const postcss = require('gulp-postcss'); const postcss = require('gulp-postcss');
const tsProject = ts.createProject(path.resolve(__dirname, '../tsconfig.json')); const tsConfig = path.resolve(__dirname, '../tsconfig.json');
const isProduction = process.env.NODE_ENV === 'production'; const isProduction = process.env.NODE_ENV === 'production';
const src = path.join(__dirname, '../packages'); const src = path.join(__dirname, '../packages');
const dist = path.join(__dirname, isProduction ? '../dist' : '../example/dist'); const libDir = path.resolve(__dirname, '../lib');
const esDir = path.resolve(__dirname, '../dist');
const exampleDir = path.resolve(__dirname, '../example/dist');
function copy(ext) { const libConfig = {
return gulp.src(`${src}/**/*.${ext}`).pipe(gulp.dest(dist)); target: 'es5',
} lib: ['es2015', 'es2017', 'dom'],
module: 'commonjs',
declaration: false
};
function compileLess() { const compileLess = dist => () =>
gulp gulp
.src(`${src}/**/*.less`) .src(`${src}/**/*.less`)
.pipe(less()) .pipe(less())
@ -34,26 +39,36 @@ function compileLess() {
}) })
) )
.pipe(gulp.dest(dist)); .pipe(gulp.dest(dist));
}
function compileTs() { const compileTs = (dist, config) => () => {
tsProject const tsProject = ts.createProject(tsConfig, config);
return tsProject
.src() .src()
.pipe(tsProject()) .pipe(tsProject())
.on('error', () => {}) .on('error', () => {})
.pipe(gulp.dest(dist)); .pipe(gulp.dest(dist));
};
const copy = (dist, ext) => () =>
gulp.src(`${src}/**/*.${ext}`).pipe(gulp.dest(dist));
const compile = (dist, config) =>
gulp.parallel(
compileTs(dist, config),
compileLess(dist),
copy(dist, 'wxml'),
copy(dist, 'wxs'),
copy(dist, 'json')
);
if (isProduction) {
gulp.series(compile(esDir), compile(libDir, libConfig))();
} else {
compile(exampleDir)();
gulp.watch(`${src}/**/*.ts`, compileTs(exampleDir));
gulp.watch(`${src}/**/*.less`, compileLess(exampleDir));
gulp.watch(`${src}/**/*.wxml`, copy(exampleDir, 'wxml'));
gulp.watch(`${src}/**/*.wxs`, copy(exampleDir, 'wxs'));
gulp.watch(`${src}/**/*.json`, copy(exampleDir, 'json'));
} }
const compileWxml = () => copy('wxml');
const compileJson = () => copy('json');
const compileWxs = () => copy('wxs');
if (!isProduction) {
gulp.watch(`${src}/**/*.ts`, compileTs);
gulp.watch(`${src}/**/*.less`, compileLess);
gulp.watch(`${src}/**/*.wxml`, compileWxml);
gulp.watch(`${src}/**/*.wxs`, compileWxs);
gulp.watch(`${src}/**/*.json`, compileJson);
}
gulp.parallel(compileTs, compileLess, compileWxml, compileJson, compileWxs)();

View File

@ -9,12 +9,13 @@
"dev": "node build/dev.js", "dev": "node build/dev.js",
"lint": "eslint ./packages --ext .js", "lint": "eslint ./packages --ext .js",
"release": "sh build/release.sh", "release": "sh build/release.sh",
"build:lib": "yarn && rm -rf dist && NODE_ENV=production node build/compiler.js", "build:lib": "yarn && rm -rf dist && rm -rf lib && NODE_ENV=production node build/compiler.js",
"build:site": "rm -rf docs/dist && cross-env NODE_ENV=production webpack --config build/webpack.doc.prd.js && gh-pages -d docs/dist", "build:site": "rm -rf docs/dist && cross-env NODE_ENV=production webpack --config build/webpack.doc.prd.js && gh-pages -d docs/dist",
"build:changelog": "vant-doc changelog --tag v0.5.0 changelog.generated.md" "build:changelog": "vant-doc changelog --tag v0.5.0 changelog.generated.md"
}, },
"files": [ "files": [
"dist" "dist",
"lib"
], ],
"repository": { "repository": {
"type": "git", "type": "git",