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. oracle 根据汉字返回拼音函数

    参见戴明明的博客,oracle 根据汉字返回拼音函数,由于他的博客里没有提供完整的代码,研究了一个多小时,才弄出来: 上来贴代码吧.. --------------Type Definition CR ...

  2. iScroll-5拉动刷新功能实现与iScroll-4上拉刷新的一点改进

    近来在学习移动设备的应用开发,接触了jQuery mobile,在网上查阅相关资料时发现一个叫”iScroll“的小插件.其实这个iScroll插件跟jQuery mobile没有多大关系,并不是基于 ...

  3. ASP.NET程序中动态修改web.config中的设置项目(后台CS代码)

    using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Dra ...

  4. Hibernate事务与并发问题处理(乐观锁与悲观锁)

    目录 一.数据库事务的定义 二.数据库事务并发可能带来的问题 三.数据库事务隔离级别 四.使用Hibernate设置数据库隔离级别 五.使用悲观锁解决事务并发问题 六.使用乐观锁解决事务并发问题 Hi ...

  5. java.sql.DataTruncation: Data truncation

    问题一: 用jdbc插入数据时,当数据库表中某列设置的长度小于要插入的字符的实际长度时就会抛出此异常. 如:数据表中某列char [4],长度为4,插入:"Hello"时,字符&q ...

  6. iOS application: how to clear notifications?

    http://stackoverflow.com/questions/8682051/ios-application-how-to-clear-notifications up vote105down ...

  7. C# 实例化顺序

    static class Program { static void Main() { BaseB baseb = new BaseB(); baseb.MyFun(); Console.ReadKe ...

  8. C#.NET开源项目、机器学习、商务智能

    所以原谅我,不能把所有的都发上来,太杂了,反而不好. 1..NET时间周期处理组件 这个组件很小,主要是对时间日期,特别是处理时间间隔以及时间范围非常方便.虽然.NET自带了时间日期的部分功能,但可能 ...

  9. ODAC连接远程Oracle数据库时,数据源名称orcl改为gscloud

    今天用ODAC连接远程Oracle数据库时,怎么也连接不上, 更改配置文件的tnsname.ora,使之都一样,并完全配置正确还是出现错误,连接不上. 最后请大神一世,原来是数据源名称的问题. 把数据 ...

  10. android——创建camera应用(译)

     只是选择相机部分来翻译.下面是主要内容 有些开发者可能需要Camera的接口,来定制自己程序的外观和特殊功能.创建自定义的Camera界面比使用using an Intent需要编写更多的代码,但是 ...