javascript - browserify/watchify 运行后触发 grunt 任务

标签 javascript gruntjs browserify watchify

我正在尝试通过 grunt/browserify 构建我的 JS 包。我还使用 grunt 进行 scss 编译。为此,我使用 grunt-watch 在更改时触发 scss 编译。

我希望 JS-browserify 具有相同的行为。 grunt-browserify 带有 "watch"选项,它的作用非常好。

我唯一的问题是:我想在“重新浏览”后收到通知。对于 SCSS,我使用 grunt-notify。但是我没有找到任何方法在 browserify-watch 之后触发 grunt 任务。

我的 gruntfile 摘录:

var gruntOptions = {

    notify: {
        browserify_node_modules: {
            options: {
                title: "Browserify",
                message: "node_modules build"
            }
        }
    },

    browserify: {
        node_modules: {
            src: ["node_modules.js"],
            dest: "trunk/js/lib/node_modules.js",
            options: {
                watch: true,
            }
        }
    }
};

最佳情况:

            options: {
                watch: true,
                finishTask: "notify:browserify_node_modules"
            }

谢谢!

最佳答案

您可以检查 Browserify 生成的文件是否已更改,然后触发任务。

在 Grunt 中安装 watch 任务:

npm install grunt-contrib-watch --save-dev

Gruntfile.js 中配置 watch 任务:

grunt.initConfig({

    // other tasks

    your_task: {
        // ...
    },

    watch: {
        dev: {
            files: 'trunk/js/lib/node_modules.js', // file generated by Browserify
            options: { spawn: false },
            tasks: ['your_task']
        }
    }
});

grunt.loadNpmTasks('grunt-contrib-watch');

关于javascript - browserify/watchify 运行后触发 grunt 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36086471/

相关文章:

javascript - 具有不规则间隔和文本的 Highchart 时间数据

javascript - 动态添加内容到表单字段时,jQuery .change() 不会发生

javascript - Meteor App 中的文件上传

javascript - 如何使用 Grunt 将 mains 文件复制到特定文件夹

gruntjs - 在 (grunt-contrib-)htmlmin 中禁用标签完成

javascript - 异步模块总是异步的吗?

javascript - 在 HTML 中使用 Node.js 模块

javascript - 在使用 window.location 重定向后的弹出窗口中,window.close 变为未定义

angularjs - 在遇到 karma 暂停后,如何让 grunt watch 继续?

javascript - 使用 browserify 创建多个对象