What we want is when the server side Node.js files have been changed, we want to use browserify to bundle all file and output just one file and later to show the console result in the browser.

For this, frist we need auto-watch: grunt-contrib-watch:

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

Then we also install grunt-browserify:

npm install grunt-browserify --save-dev

Create 'GruntFile.js' and put in:

module.exports = function(grunt) {

    grunt.initConfig({
browserify: {
'server-build/app.js': ['server/**/*.js']
},
watch: {
files: ["server/**/*.js"],
tasks: ['browserify']
}
}); grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-watch');
}

What it says is that:

  1. Watch all the files under server dir, including nested dir and theirs files.

  2. Once those files have been modified, run browserify task.

  3. The browserify task says that: bundle all the files in server dir and output to server-build dir's app.js file.

Then you can run:

grunt watch

Test file:

server/app.js:

var test = require('./test');
console.log(test());

server/test.js:

module.exports = function(){
return "Hello World";
}

More:

http://codeofrob.com/entries/grunt+browserify+npm+application=success.html

https://github.com/jmreidy/grunt-browserify

[Whole Web] [Node.js] [Browserify] [Grunt] Automation task with grunt-browserify & grunt-contrib-watch的更多相关文章

  1. 【win7下安装node.js错误:roling back action】与【"grunt" 不是内部或外部命令】 解决方法

    [win7下安装node.js错误:roling back action] 解决方法: Node.js 服务器端的JavaScript Node.js 是一个基于Chrome JavaScript 运 ...

  2. [Whole Web] [Node.js] Using npm run to launch local scripts

    npm run allows you to configure scripts inside of your package.json file which can access locally in ...

  3. [Whole Web, Node.js PM2] Loggin with PM2

    Add config for app's log and error log for PM2. { "apps": [{ "name": "App1& ...

  4. [Whole Web, Node.js, PM2] Configuring PM2 for Node applications

    In this lesson, you will learn how to configure node apps using pm2 and a json config file. Let's sa ...

  5. [Whole Web] [Node.js, PM2] Controlling runaway apps using pm2

    shows how to enable features in your pm2 config file that allow you to prevent runaway apps from bri ...

  6. [Whole Web, Node.js, PM2] Restarting your node.js app on code change using pm2

    Aadd watch to the config.json file: { "apps": [{ "name": "App1", " ...

  7. 进击Node.js基础(一)

    一.前言 1:Node.js本质上是用chrome浏览器 v8引擎 使用c++编写的JS运行环境 2:相比于JS没有浏览器安全级的限制,额外提供了一些系统级的API:文件读写,进程管理,网络通信等. ...

  8. Node.js开发Web后台服务

    一.简介 Node.js 是一个基于Google Chrome V8 引擎的 JavaScript 运行环境.Node.js 使用了一个事件驱动.非阻塞式 I/O 的模型,使其轻量又高效.Node.j ...

  9. 认识Web前端、Web后端、桌面app和移动app新开发模式 - 基于Node.js环境和VS Code工具

    认识Web.桌面和移动app新开发模式 - 基于Node.js环境和VS Code工具 一.开发环境的搭建(基于win10) 1.安装node.js和npm 到node.js官网下载安装包(包含npm ...

随机推荐

  1. No Hibernate Session bound to thread, and configuration does not allow

    今天晚上挺悲催的,遇到了这个问题花费我很长时间,现在总结如下: 到这这种情况的发生有两种情况: 1,没有配置事物只要在Spring配置文件中添加如下代码: <bean id="txMa ...

  2. 对DataTable里数据进行排序

    在日常开发过程中,有一个DataTable集合,里面有很多字段,现在要求针对某一列进行排序,如果该列为数字的话,进行ASC即可实现,但是该字段类型为string,此时排序就有点不正确了. 我也不多废话 ...

  3. Spring3中用注解直接注入properties中的值

    在bean(可是controller, service, dao等了)中,使用@Value注解: @Service public class TestService{ @Value("${s ...

  4. 【 D3.js 进阶系列 】 进阶总结

    进阶系列的文章从去年10月开始写的,晃眼又是4个多月了,想在年前总结一下. 首先恭祝大家新年快乐.今年是羊年吧.前段时间和朋友聊天,聊到十二生肖里为什么没猫,我张口就道:不是因为十二生肖开会的时候猫迟 ...

  5. 剑指Offer:互为变位词

    // 判断两个单词是否互为变位词: 如果两个单词中的字母相同,并且每个字母出现的次数也相同, 那么这两个单词互为变位词 #include <stdio.h> #include <st ...

  6. HDU 4389 X mod f(x)

    题意:求[A,B]内有多少个数,满足x % f(x) == 0. 解法:数位DP.转化为ans = solve(b) - solve(a - 1).设dp[i][sum][mod][r]表示长度为i, ...

  7. JMX学习一

    JMX        即 Java Management Extensions   Java管理扩展MBean   即 managed beans                         被管 ...

  8. Kooboo CMS的安装步骤

    Kooboo CMS的安装步骤 来自Kooboo document 跳转到: 导航, 搜索 http://www.microsoft.com/web/gallery/install.aspx?appi ...

  9. 【JMeter】Jmeter引入第三方jar包

    Jmeter做remoteService,里面用到一个实体:clickEntity,是在一个第三方jar包定义的:com.bj58.opt.ad_logparser-0.0.18-SNAPSHOT.j ...

  10. 关于Excel中的需求或者是用例导入到QC中遇到的问题

    Excel 中导入用例到QC时,会提示如图所示的错误信息:   解决方案: 我的电脑-->属性->高级-->性能设置-->添加QC程序