1

我正在使用gruntMEAN.JS

在 git中的最后一次提交之前,我执行grunt build并创建了dist目录:application.jsapplication.min.cssapplication.min.js

NODE_ENV变量development.

我在 中添加新引用index.html,并对旧引用进行注释。该项目运行完美,速度更快!

今天,我也想做同样的事情,我重复了所有过程:我先删除/dist目录(Okey,不是必需的,但我做了),然后我执行grunt build,这个命令在 中生成新文件/dist,等等。

但是... grunt build我所做.js的新代码不会使用我编写的新代码生成文件。在新的修改之前再次生成旧代码......

为什么?

我怎么解决这个问题?

gruntfile.js

'use strict';

module.exports = function(grunt) {
// Unified Watch Object
var watchFiles = {
    serverViews: ['app/views/**/*.*'],
    serverJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js'],
    clientViews: ['public/modules/**/views/**/*.html'],
    clientJS: ['public/js/*.js', 'public/modules/**/*.js'],
    clientCSS: ['public/modules/**/*.css'],
    mochaTests: ['app/tests/**/*.js']
};

// Project Configuration
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    watch: {
        serverViews: {
            files: watchFiles.serverViews,
            options: {
                livereload: true
            }
        },
        serverJS: {
            files: watchFiles.serverJS,
            tasks: ['jshint'],
            options: {
                livereload: true
            }
        },
        clientViews: {
            files: watchFiles.clientViews,
            options: {
                livereload: true,
            }
        },
        clientJS: {
            files: watchFiles.clientJS,
            tasks: ['jshint'],
            options: {
                livereload: true
            }
        },
        clientCSS: {
            files: watchFiles.clientCSS,
            tasks: ['csslint'],
            options: {
                livereload: true
            }
        }
    },
    jshint: {
        all: {
            src: watchFiles.clientJS.concat(watchFiles.serverJS),
            options: {
                jshintrc: true
            }
        }
    },
    csslint: {
        options: {
            csslintrc: '.csslintrc',
        },
        all: {
            src: watchFiles.clientCSS
        }
    },
    uglify: {
        production: {
            options: {
                mangle: false
            },
            files: {
                'public/dist/application.min.js': 'public/dist/application.js'
            }
        }
    },
    cssmin: {
        combine: {
            files: {
                'public/dist/application.min.css': '<%= applicationCSSFiles %>'
            }
        }
    },
    nodemon: {
        dev: {
            script: 'server.js',
            options: {
                nodeArgs: ['--debug'],
                ext: 'js,html',
                watch: watchFiles.serverViews.concat(watchFiles.serverJS)
            }
        }
    },
    'node-inspector': {
        custom: {
            options: {
                'web-port': 1337,
                'web-host': 'localhost',
                'debug-port': 5858,
                'save-live-edit': true,
                'no-preload': true,
                'stack-trace-limit': 50,
                'hidden': []
            }
        }
    },
    ngAnnotate: {
        production: {
            files: {
                'public/dist/application.js': '<%= applicationJavaScriptFiles %>'
            }
        }
    },
    concurrent: {
        default: ['nodemon', 'watch'],
        debug: ['nodemon', 'watch', 'node-inspector'],
        options: {
            logConcurrentOutput: true,
            limit: 10
        }
    },
    env: {
        test: {
            NODE_ENV: 'test'
        },
        secure: {
            NODE_ENV: 'secure'
        }
    },
    mochaTest: {
        src: watchFiles.mochaTests,
        options: {
            reporter: 'spec',
            require: 'server.js'
        }
    },
    karma: {
        unit: {
            configFile: 'karma.conf.js'
        }
    }
});

// Load NPM tasks
require('load-grunt-tasks')(grunt);

// Making grunt default to force in order not to break the project.
grunt.option('force', true);

// A Task for loading the configuration object
grunt.task.registerTask('loadConfig', 'Task that loads the config into a grunt option.', function() {
    var init = require('./config/init')();
    var config = require('./config/config');

    grunt.config.set('applicationJavaScriptFiles', config.assets.js);
    grunt.config.set('applicationCSSFiles', config.assets.css);
});

// Default task(s).
grunt.registerTask('default', ['lint', 'concurrent:default']);

// Debug task.
grunt.registerTask('debug', ['lint', 'concurrent:debug']);

// Secure task(s).
grunt.registerTask('secure', ['env:secure', 'lint', 'concurrent:default']);

// Lint task(s).
grunt.registerTask('lint', ['jshint', 'csslint']);

// Build task(s).
grunt.registerTask('build', ['lint', 'loadConfig', 'ngAnnotate', 'uglify', 'cssmin']);

// Test task.
grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']);
};

谢谢!

4

0 回答 0