用于开发/生产环境的备用 grunt.js 任务

2024-05-09

我真的很希望能够拥有一个开发 grunt 文件并使用相同的文件作为脚本的生产版本。

我已经尝试过建议,但是当尝试调用 dev/prod 参数时,我的脚本将会失败。我相信答案是针对旧版本的 grunt,或者可能是我正在使用的插件。

module.exports = function (grunt) {

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

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        compass: {
            dev: {
                options: {
                    config: 'config.rb',
                    force: true,
                    livereload: true
                }
            }
        },
        uglify: {
            build: {
                src: ['docroot/js/*.js', 'docroot/components/**/*.js'],
                dest: 'docroot/dis/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...');
                },
                livereload: true
            },
            sass: {
                files: ['docroot/sass/*.scss'],
                tasks: ['compass:dev']
            },
            /* watch and see if our javascript files change, or new packages are installed */
            js: {
                files: '<%= uglify.build.src %>',
                tasks: ['uglify']
            },
            /* watch our files for change, reload */
            livereload: {
                files: ['*.html', 'docroot/css/*.css', 'docroot/img/*', 'docroot/js/{main.min.js, plugins.min.js}'],
                options: {
                    livereload: true
                }
            }
        }
    });


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

真的,只要我可以通过调用它们来运行两个版本,例如:

 grunt //local
 grunt prod //live

然后我可以使用脚本和加载内容。


您也可以只注册一个调用任务数组的任务

grunt.registerTask('prod', ['tasks1','task2']); 

在你的默认任务之前,那就是

$ grunt prod
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

用于开发/生产环境的备用 grunt.js 任务 的相关文章

随机推荐