微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angularjs – 防止gulp缩小本地机器上的代码

我用[RDash角度仪表板] [1]开始了一个使用gulp的项目.
这是我第一次使用gulp,问题是当我在本地工作时我无法调试,因为它缩小了css / js / html文件.

如何在本地工作时防止吞咽缩小?

这是我在gulpfile.js上的内容

var gulp = require('gulp'),usemin = require('gulp-usemin'),wrap = require('gulp-wrap'),connect = require('gulp-connect'),watch = require('gulp-watch'),minifyCss = require('gulp-minify-css'),minifyJs = require('gulp-uglify'),concat = require('gulp-concat'),less = require('gulp-less'),rename = require('gulp-rename'),minifyHTML = require('gulp-minify-html');

var paths = {
scripts: 'src/js/**/*.*',styles: 'src/less/**/*.*',images: 'src/img/**/*.*',templates: 'src/templates/**/*.html',index: 'src/index.html',bower_fonts: 'src/components/**/*.{ttf,woff,eof,svg}',};

/**
 * Handle bower components from index
   */
   gulp.task('usemin',function() {
return gulp.src(paths.index)
    .pipe(usemin({
        js: [minifyJs(),'concat'],css: [minifyCss({keepSpecialComments: 0}),}))
    .pipe(gulp.dest('dist/'));
});

/**
 * copy assets
   */
gulp.task('build-assets',['copy-bower_fonts']);

gulp.task('copy-bower_fonts',function() {
return gulp.src(paths.bower_fonts)
    .pipe(rename({
        dirname: '/fonts'
    }))
    .pipe(gulp.dest('dist/lib'));
});

/**
 * Handle custom files
 */
gulp.task('build-custom',['custom-images','custom-js','custom-less','custom-templates']);

gulp.task('custom-images',function() {
return gulp.src(paths.images)
    .pipe(gulp.dest('dist/img'));
});

gulp.task('custom-js',function() {
return gulp.src(paths.scripts)
    .pipe(minifyJs())
    .pipe(concat('dashboard.min.js'))
    .pipe(gulp.dest('dist/js'));
});

gulp.task('custom-less',function() {
return gulp.src(paths.styles)
    .pipe(less())
    .pipe(gulp.dest('dist/css'));
});

gulp.task('custom-templates',function() {
return gulp.src(paths.templates)
    .pipe(minifyHTML())
    .pipe(gulp.dest('dist/templates'));
});

/**
 * Watch custom files
 */
gulp.task('watch',function() {
gulp.watch([paths.images],['custom-images']);
gulp.watch([paths.styles],['custom-less']);
gulp.watch([paths.scripts],['custom-js']);
gulp.watch([paths.templates],['custom-templates']);
gulp.watch([paths.index],['usemin']);
});

/**
 * Live reload server
 */
gulp.task('webserver',function() {
connect.server({
    root: 'dist',livereload: true,port: 8888
});
});

gulp.task('livereload',function() {
gulp.src(['dist/**/*.*'])
    .pipe(watch())
    .pipe(connect.reload());
});

/**
 * Gulp tasks
 */
gulp.task('build',['usemin','build-assets','build-custom']);
gulp.task('default',['build','webserver','livereload','watch']);

解决方法

您应该添加gulp-minify并按如下方式使用它:

var minify = require('gulp-minify');

gulp.task('compress',function() {
  gulp.src('lib/*.js')
    .pipe(minify({
        exclude: ['tasks'],ignoreFiles: ['.combo.js','-min.js']
    }))
    .pipe(gulp.dest('dist'))
});

将您不想缩小的文件传递给排除.

在您的代码中,您已指定要在此处缩小所有文件

gulp.task('usemin',function() {
   return gulp.src(paths.index)
    .pipe(usemin({
        js: [minifyJs(),}))
    .pipe(gulp.dest('dist/'));
});

排队

.pipe(usemin({..})

只是不要使用这个usemin任务,你应该没事

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐