Commit 3b5a19b4 authored by rockyl's avatar rockyl

增加自动识别paths配置

parent 3ebfd9e0
......@@ -2,6 +2,7 @@
* Created by rockyl on 2018/7/9.
*/
const path = require('path');
const gulp = require('gulp');
const rollup = require('rollup');
const {uglify} = require('rollup-plugin-uglify');
......@@ -18,6 +19,29 @@ exports.setCallback = function (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 () {
let plugins = [
resolve({
......@@ -25,7 +49,7 @@ gulp.task('compileTs', async function () {
}),
typescript({
typescript: require('typescript'),
include: ['**/*.ts', '../common/**/*.ts', '../../src/**/*.ts'],
include: tsPaths,
}),
commonjs(),
];
......@@ -68,12 +92,12 @@ gulp.task('watch', function () {
gulp.watch('src/**', ['compile']);
});
gulp.task('dev', ['compileTs', 'watch'], function(cb){
gulp.task('dev', ['compileTs', 'watch'], function (cb) {
completeCallback && completeCallback('success');
cb();
});
gulp.task('compile', ['compileTs'], function(cb){
gulp.task('compile', ['compileTs'], function (cb) {
completeCallback && completeCallback('success');
cb();
});
......@@ -82,7 +106,7 @@ gulp.task('build', async function () {
currentMode = 'build';
version = Math.floor(Date.now() / 1000).toString();
releasePath = `dist/${version}/`;
gulp.start(['compileTs', ], function(){
gulp.start(['compileTs',], function () {
console.log('build success! \nversion:', 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