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. [原]Unity3D深入浅出 - 物理引擎之刚体部件(Rigidbody)

    在虚拟世界中,任何物体都是没有活力的,要想变的真实,Rigidbody是必不可少的组件,下面介绍Rigidbody的各个属性: Mass:质量 Drag:阻力,对象在运动时遇到的空气阻力,0表示没有空 ...

  2. 【转】 Android 开发 之 JNI入门 - NDK从入门到精通

    原文网址:http://blog.csdn.net/shulianghan/article/details/18964835 NDK项目源码地址 : -- 第一个JNI示例程序下载 : GitHub  ...

  3. unix network programming(3rd)Vol.1 [第13~15章]《读书笔记系列》

    第13章 守护进程和inetd 超级服务器 syslog() daemon_init() setuid() setgid() 第14章 高级IO 标准I/O函数库,支持3种缓冲 缓冲(读写存储设备(硬 ...

  4. gem install走代理,速度刚刚的

    有个树莓pi,安装了shadowsocks 和 cow ,做代理,走ipv6,学校不收ipv6流量钱.速度也不错,快的下载可达10M/s. gem install xx遇到墙了. nano ~/.ge ...

  5. HDU-4651 Partition 整数拆分,递推

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4651 题意:求n的整数拆为Σ i 的个数. 一般的递归做法,或者生成函数做法肯定会超时的... 然后要 ...

  6. HDU-4607 Park Visit bfs | DP | dfs

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4607 首先考虑找一条最长链长度k,如果m<=k+1,那么答案就是m.如果m>k+1,那么最 ...

  7. asp.net 分析器错误消息: 文件.aspx.cs”不存在错误

    发布webapplication时后老是报告分析器错误消息: 文件.aspx.cs”不存在错误,差点抓狂,后来在网上搜到原因是: <%@ Page Language="C#" ...

  8. 【转】hive简介安装 配置常见问题和例子

    原文来自:  http://blog.csdn.net/zhumin726/article/details/8027802 1 HIVE概述 Hive是基于Hadoop的一个数据仓库工具,可以将结构化 ...

  9. Android权威编程指南读书笔记(1-2章)

    第一章 Android应用初体验 1.4用户界面设计 <?xml version="1.0" encoding="utf-8"?> ADT21开发版 ...

  10. A Tour of Go Channels

    Channels are a typed conduit through which you can send and receive values with the channel operator ...