您好我正在使用从here下载的Angular 2项目
原作所做的是从app文件夹中获取所有文件,编译成打字稿,捆绑它们并将它们放在dist文件夹中。
唯一的问题是,我在app文件夹中有子文件夹和文件,它无论如何都不会捆绑,因此会抛出错误。
XMLHttpRequest无法加载file:///profile.component.html
var gulp = require('gulp');
var shell = require('gulp-shell');
var clean = require('gulp-clean');
var htmlreplace = require('gulp-html-replace');
var runSequence = require('run-sequence');
var Builder = require('systemjs-builder');
var builder = new Builder('', 'systemjs.config.js');
var bundleHash = new Date().getTime();
var mainBundleName = bundleHash + '.main.bundle.js';
var vendorBundleName = bundleHash + '.vendor.bundle.js';
// This is main task for production use
gulp.task('dist', function(done) {
runSequence('clean', 'compile_ts', 'bundle', 'copy_assets', function() {
done();
});
});
gulp.task('bundle', ['bundle:vendor', 'bundle:app'], function () {
return gulp.src('index.html')
.pipe(htmlreplace({
'app': mainBundleName,
'vendor': vendorBundleName
}))
.pipe(gulp.dest('./dist'));
});
gulp.task('bundle:vendor', function () {
return builder
.buildStatic('app/vendor.js', './dist/' + vendorBundleName)
.catch(function (err) {
console.log('Vendor bundle error');
console.log(err);
});
});
gulp.task('bundle:app', function () {
return builder
.buildStatic('app/main.js', './dist/' + mainBundleName)
.catch(function (err) {
console.log('App bundle error');
console.log(err);
});
});
gulp.task('compile_ts', ['clean:ts'], shell.task([
'tsc'
]));
gulp.task('copy_assets', function() {
return gulp.src(['./assets/**/*'], {base:"."})
.pipe(gulp.dest('./dist'));
});
gulp.task('clean', ['clean:ts', 'clean:dist']);
gulp.task('clean:dist', function () {
return gulp.src(['./dist'], {read: false})
.pipe(clean());
});
gulp.task('clean:ts', function () {
return gulp.src(['./app/**/*.js', './app/**/*.js.map'], {read: false})
.pipe(clean());
});
我道歉,我对此很陌生