Commit 3b5a19b4 authored by rockyl's avatar rockyl

增加自动识别paths配置

parent 3ebfd9e0
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Created by rockyl on 2018/7/9. * Created by rockyl on 2018/7/9.
*/ */
const path = require('path');
const gulp = require('gulp'); const gulp = require('gulp');
const rollup = require('rollup'); const rollup = require('rollup');
const {uglify} = require('rollup-plugin-uglify'); const {uglify} = require('rollup-plugin-uglify');
...@@ -18,6 +19,29 @@ exports.setCallback = function (callback) { ...@@ -18,6 +19,29 @@ exports.setCallback = function (callback) {
completeCallback = callback; completeCallback = callback;
}; };
const tsPaths = ['**/*.ts'];
const tsconfig = require(path.resolve('tsconfig.json'));
const pathsConfig = tsconfig.compilerOptions.paths;
//console.log(pathsConfig);
if (pathsConfig) {
for (let key in pathsConfig) {
let paths = pathsConfig[key];
for(let path of paths){
if (path[path.length - 1] === '*') {
path += '*/*.ts';
}else{
try{
path = path.replace(/index$/, '**/*.ts')
}catch (e) {
console.log(e);
}
}
tsPaths.push(path);
}
}
}
//console.log(tsPaths);
gulp.task('compileTs', async function () { gulp.task('compileTs', async function () {
let plugins = [ let plugins = [
resolve({ resolve({
...@@ -25,7 +49,7 @@ gulp.task('compileTs', async function () { ...@@ -25,7 +49,7 @@ gulp.task('compileTs', async function () {
}), }),
typescript({ typescript({
typescript: require('typescript'), typescript: require('typescript'),
include: ['**/*.ts', '../common/**/*.ts', '../../src/**/*.ts'], include: tsPaths,
}), }),
commonjs(), commonjs(),
]; ];
...@@ -68,12 +92,12 @@ gulp.task('watch', function () { ...@@ -68,12 +92,12 @@ gulp.task('watch', function () {
gulp.watch('src/**', ['compile']); gulp.watch('src/**', ['compile']);
}); });
gulp.task('dev', ['compileTs', 'watch'], function(cb){ gulp.task('dev', ['compileTs', 'watch'], function (cb) {
completeCallback && completeCallback('success'); completeCallback && completeCallback('success');
cb(); cb();
}); });
gulp.task('compile', ['compileTs'], function(cb){ gulp.task('compile', ['compileTs'], function (cb) {
completeCallback && completeCallback('success'); completeCallback && completeCallback('success');
cb(); cb();
}); });
...@@ -82,7 +106,7 @@ gulp.task('build', async function () { ...@@ -82,7 +106,7 @@ gulp.task('build', async function () {
currentMode = 'build'; currentMode = 'build';
version = Math.floor(Date.now() / 1000).toString(); version = Math.floor(Date.now() / 1000).toString();
releasePath = `dist/${version}/`; releasePath = `dist/${version}/`;
gulp.start(['compileTs', ], function(){ gulp.start(['compileTs',], function () {
console.log('build success! \nversion:', version); console.log('build success! \nversion:', version);
completeCallback && completeCallback(version); completeCallback && completeCallback(version);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment