我正在尝试用gulp中的代码缩小我的代码我可以创建一个名为_build的文件夹,我在其中优化我的代码,缩小它并返回它uglify 并且显然它已缩小但它不再是angular.js的有效代码,例如:
angularRoutingApp.controller('homeController', function($scope,$state,$http,$timeout,$window,alerta,preload){
到
angularRoutingApp.controller("homeController",function(e,o,i,a,n,r,t)
在这行代码中我将控制器转换为uglify
controllers:[$.uglify()],
这是我的代码:
gulp.task('minify-js', function() {
gulp.src('js/*.js')
.pipe($.uglify())
.pipe(gulp.dest('./_build/'));
});
gulp.task('minify-css', function() {
gulp.src(['./css/**/*.css'])
.pipe($.rename({suffix: '.min'}))
.pipe($.minifyCss({keepBreaks:true}))
.pipe(gulp.dest('./css/'))
.pipe(gulp.dest('./_build/css/'));
});
gulp.task('minify-html', function() {
var opts = {
comments: true,
spare: true,
conditionals: true
};
gulp.src('./*.html')
.pipe($.minifyHtml(opts))
.pipe(gulp.dest('./_build/'));
});
gulp.task('fonts', function() {
gulp.src('./fonts/**/*.{ttf,woff,eof,eot,svg}')
.pipe($.changed('./_build/fonts'))
.pipe(gulp.dest('./_build/fonts'));
});
gulp.task('server', function(done) {
return browserSync({
server: {
baseDir: './'
}
}, done);
});
gulp.task('server-build', function(done) {
return browserSync({
server: {
baseDir: './_build/'
}
}, done);
});
gulp.task('clean:build', function (cb) {
del([
'./_build/'
// if we don't want to clean any file we can use negate pattern
//'!dist/mobile/deploy.json'
], cb);
});
require('events').EventEmitter.prototype._maxListeners = 100;
gulp.task('usemin', function() {
return gulp.src('./index.html')
// add templates path
.pipe($.htmlReplace({
'templates': '<script type="text/javascript" src="js/templates.js"></script>'
}))
.pipe($.usemin({
css: [$.minifyCss(), 'concat'],
libs: [$.uglify()],
nonangularlibs: [$.uglify()],
angularlibs: [$.uglify()],
controllers:[$.uglify()],
contservicesapp:[$.uglify()],
services:[$.uglify()],
appcomponents: [$.uglify()],
mainapp: [$.uglify()],
templates:[$.uglify()],
directives:[$.uglify()]
}))
.pipe(gulp.dest('./_build/'));
});
我该如何解决?