Jerome Ansia
Jerome Ansia

Reputation: 6892

Grunt my code is duplicated in concat.js

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)

Upvotes: 0

Views: 684

Answers (1)

fiskeben
fiskeben

Reputation: 3467

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

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.

Upvotes: 2

Related Questions