Grunt我的代码重复在concat.js中 [英] Grunt my code is duplicated in concat.js

查看:114
本文介绍了Grunt我的代码重复在concat.js中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的grunt配置文件:

Here is my grunt config file:

module.exports = function (grunt) {

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-karma');
    grunt.loadNpmTasks('grunt-contrib-sass');

    grunt.initConfig({
        uglify: {
            build: {
                src: 'app/concat.js',
                dest: 'app/concat.min.js'
            }
        },

        concat: {
            options: {
                separator: ';',
            },
            dist: {
                src: ['app/js/**/*.js', '!app/concat.js',
                dest: 'app/concat.js'
            }
        },

        watch: {
            karma: {
                files: ['app/js/**/*.js', 'jasmine/spec/**/*.js'],
                tasks: ['karma:unit:run']
            },

            concat: {
                files: ['app/js/**/*.js', '!app/concat.js'],
                tasks: ['concat']
            },

            live: {
                files: ['app/js/**/*.js', '!app/concat.js', 'app/partials/**/*.html', 'WEB-INF/jsp/panther.html', 'css/new_style.css', 'css/style.css'],
                options: {
                    livereload: true
                }
            }
        },

        karma: {
            unit: {
                configFile: 'jasmine/karma.conf.js',
                background: true
            }
        },

        sass: {
            dist: {
                files: {
                    'css/new_style.css': 'css/sass/new_style.scss'
                }
            }
        }
    });


    grunt.registerTask('default', ['karma:unit:start', 'concat', 'watch']);
}

我做了一个手表,并在代码更改时触发了单元测试和连接,

I do a watch and on code change i trigger the unit testing and concatenation,

我的感觉是这条线:

My feeling is that this line:

src: ['app/js/**/*.js', '!app/concat.js',

工作不正常(至少在第二部分中)

is not working properly (at least for the second part)

推荐答案

看起来您正在构建相同的目录/文件作为您的来源。我认为这是一个坏主意。

It looks like you're building to the same directory/files as your source. I think that's a bad idea.

您应该将您正在处理的文件保存在一个目录中(例如 src )并让Grunt任务输出到另一个(例如 app )。这样至少可以降低重复的风险。

You should keep the files you're working on in one directory (for instance src) and let Grunt tasks output to another (for instance app). That would at least decrease the risk of duplication.

如果您有一项任务需要处理另一个任务的输出,那么让第一个任务输出到一个临时目录并让第二项任务从中读取。

If you have one task that needs to work on the output of another task, let the first task output to a temporary directory and let the second task read from it.

这篇关于Grunt我的代码重复在concat.js中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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