如何忽略文件grunt uglify [英] How to ignore files grunt uglify

查看:283
本文介绍了如何忽略文件grunt uglify的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我刚刚在30分钟前开始使用grunt。所以请耐心等待。



但是我有一个相当简单的脚本,它会查看我的js,然后将它压缩到一个文件中。



代码

 use strict; 
module.exports = function(grunt){

//载入所有grunt任务
require('matchdep')。filterDev('grunt - *')。forEach(grunt .loadNpmTasks);

grunt.initConfig({
pkg:grunt.file.readJSON('package.json'),
uglify:{
options:{
美化:true,
report:'gzip'
},
build:{
src:['docroot / js / *。js','docroot / components / pages / * .js','docroot / components / plugins / *。js'],
dest:'docroot / js / main.min.js'
}
},
手表:{
options:{
dateFormat:function(time){
grunt.log.writeln('手表在'+ time +'ms'+'(new Date() ).toString());
grunt.log.writeln('等待更多...');
}
},
js:{
files:'<%= uglify.build.src%>',
tasks:['uglify']
}
}
});

grunt.registerTask('default','watch');


问题



我的main.min.js每次都被包含在编译中。这意味着我的min.js正在获得2x,4x,8x,16x等等。最好的解决方法是添加一个异常并忽略 main.min.js


解决方案

在src数组的 end 中,添加

 '!docroot / js / main.min.js'

这将排除它。 !!把它变成排除。



http://gruntjs.com/api/grunt.file#grunt.file.expand


路径匹配模式开始!将从返回的数组中排除。模式按顺序处理,所以包含和排除顺序很重要。

这不是特定于grunt uglify,而是任何使用指定文件的grunt约定将以这种方式工作。



作为一般性建议,尽管我建议将构建的文件放在除源文件之外的其他位置。就像在根目录 dist 文件夹中一样。


Background

I've just started using grunt as of about 30mins ago. So bear with me.

But I have a rather simple script going that will look at my js and then compress it all into one file for me.

Code

"use strict";
module.exports = function (grunt) {

    // load all grunt tasks
    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        uglify: {
            options: {
                beautify: true,
                report: 'gzip'
            },
            build: {
                src: ['docroot/js/*.js', 'docroot/components/pages/*.js', 'docroot/components/plugins/*.js'],
                dest: 'docroot/js/main.min.js'
            }
        },
        watch: {
            options: {
                dateFormat: function(time) {
                    grunt.log.writeln('The watch finished in ' + time + 'ms at' + (new Date()).toString());
                    grunt.log.writeln('Waiting for more changes...');
                }
            },
            js: {
                files: '<%= uglify.build.src %>',
                tasks: ['uglify']
            }
        }
    });

    grunt.registerTask('default', 'watch');

}

Question

My main.min.js is getting included in the compile each time. Meaning my min.js is getting 2x, 4x, 8x, 16x etc etc. Is best way around this is to add an exception and ignore main.min.js?

解决方案

To the end of the src array, add

'!docroot/js/main.min.js'

This will exclude it. The ! turns it into an exclude.

http://gruntjs.com/api/grunt.file#grunt.file.expand

Paths matching patterns that begin with ! will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant.

This is not specific to grunt uglify, but any task that uses grunt convention for specifying files will work this way.

As a general advice though I would suggest putting built files somewhere else than your source files. Like in a root dist folder.

这篇关于如何忽略文件grunt uglify的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆