热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

防止gulp缩小本地机器上的代码-Preventgulptominifycodeonlocalmachine

Istartedaprojectwith[RDashangulardashboard][1]whichusinggulp.thisisthefirsttimeIwor

I started a project with [RDash angular dashboard][1] which using gulp. this is the first time I work with gulp and the problem is that while I'm working locally I can't debug because it minify css/js/html files.

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

How can I prevent from gulp to minify while working locally?

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

Here is what I have on gulpfile.js:

这是我在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}), 'concat'],
    }))
    .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']);

1 个解决方案

#1


2  

You should add gulp-minify and use it as follows:

您应该添加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'))
});

Pass the files that you dont want to minify to the exclude.

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

In your code, you have specified that you want to minify all of the files here:

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

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

In line

.pipe(usemin({..}) 

Just dont use this usemin task, and you should be fine

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


推荐阅读
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文讨论了在openwrt-17.01版本中,mt7628设备上初始化启动时eth0的mac地址总是随机生成的问题。每次随机生成的eth0的mac地址都会写到/sys/class/net/eth0/address目录下,而openwrt-17.01原版的SDK会根据随机生成的eth0的mac地址再生成eth0.1、eth0.2等,生成后的mac地址会保存在/etc/config/network下。 ... [详细]
  • 移动传感器扫描覆盖摘要:关于传感器网络中的地址覆盖问题,已经做过很多尝试。他们通常归为两类,全覆盖和栅栏覆盖,统称为静态覆盖 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • 本文介绍了计算机网络的定义和通信流程,包括客户端编译文件、二进制转换、三层路由设备等。同时,还介绍了计算机网络中常用的关键词,如MAC地址和IP地址。 ... [详细]
  • Go Cobra命令行工具入门教程
    本文介绍了Go语言实现的命令行工具Cobra的基本概念、安装方法和入门实践。Cobra被广泛应用于各种项目中,如Kubernetes、Hugo和Github CLI等。通过使用Cobra,我们可以快速创建命令行工具,适用于写测试脚本和各种服务的Admin CLI。文章还通过一个简单的demo演示了Cobra的使用方法。 ... [详细]
  • 浅解XXE与Portswigger Web Sec
    XXE与PortswiggerWebSec​相关链接:​博客园​安全脉搏​FreeBuf​XML的全称为XML外部实体注入,在学习的过程中发现有回显的XXE并不多,而 ... [详细]
  • 由于同源策略的限制,满足同源的脚本才可以获取资源。虽然这样有助于保障网络安全,但另一方面也限制了资源的使用。那么如何实现跨域呢,以下是实现跨域的一些方法。 ... [详细]
  • 本文由编程笔记#小编为大家整理,主要介绍了css回到顶部按钮相关的知识,希望对你有一定的参考价值。 ... [详细]
  • GO语言 包 if..else.. for循环 switch 数组
    包1.什么是包1.新建一个文件夹,内部写很多go文件,但是包名必须一致,改文件夹就是一个包2.作用和优点包用于组织Go源代码,提供了更好的可重用性与可读性。由于包提供了代码的封装, ... [详细]
  • 语法必须遵守的语法推荐遵守语法不做要求文件格式文件应该使用Unicode(UTF-8)编码保存。同时不要使用字节序标记(BOM)。与UTF-16和 ... [详细]
  • 二十二、D3饼图Abstract在前一章中,你已经看到了条形图是如何表示某一类数 ... [详细]
  • 本文实例为大家分享了d3.js图形拖拽的具体代码,供大家参考,具体内容如下 ... [详细]
  • 本文介绍了贝叶斯垃圾邮件分类的机器学习代码,代码来源于https://www.cnblogs.com/huangyc/p/10327209.html,并对代码进行了简介。朴素贝叶斯分类器训练函数包括求p(Ci)和基于词汇表的p(w|Ci)。 ... [详细]
author-avatar
捕鱼达人2602906405
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有