2

我在本地开发期间使用 Watchify(通过 grunt-browserify)进行快速编译:

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    browserify: {
        app: {
            src: './src/app.js',
            dest: 'build/js/app.js'
        },
        options: {
            // next two lines for watchify + watch instead of browserify
            watch: true,
            keepAlive: true,
            transform: ['node-lessify', 'node-underscorify'],
            debug: true,
            browserifyOptions: {
                debug:true // include source maps.  currently only available with browserify
            }
        }
    }
}

grunt.loadNpmTasks('grunt-browserify');

运行grunt browserify进入一个while true不断观察变化的循环。在构建可用于生产的捆绑包时,我希望它运行一次而不是观看。

我已经尝试过这种配置,但browserify:dev任务从不关注:

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    browserify: {
        dev: {
            src: './src/app.js',
            dest: 'build/js/app.js',
            // next two lines for watchify + watch instead of browserify
            watch: true,
            keepAlive: true
        },
        package: {
            src: './src/app.js',
            dest: 'build/js/app.js'
        },
        options: {
            transform: ['node-lessify', 'node-underscorify'],
            browserifyOptions: {
                debug:true // include source maps.  currently only available with browserify
            }
        }
    }
});

如何指定一个使用 Watchify 监视的 Browserify 任务,以及一个构建整个包并退出的任务?

4

1 回答 1

2

我的配置错误。请注意,keepAlive: false它位于作业的options命名空间中browserify:package

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    browserify: {
        dev: {
            src: './src/app.js',
            dest: 'build/js/app.js'
        },
        package: {
            src: './src/app.js',
            dest: 'build/js/app.js',
            options: {
                keepAlive: false
            }
        },
        options: {
            watch: true,
            keepAlive: true,
            transform: ['node-lessify', 'node-underscorify'],
            browserifyOptions: {
                debug:true // include source maps.  currently only available with browserify
            }
        }
    }
});
于 2014-12-10T21:29:35.443 回答