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. C语言中的位拷贝与值拷贝浅谈(转载)

    注:C语言实现的PHP变量的赋值过程中,就涉及到了 深拷贝和浅拷贝 位拷贝拷贝的是地址(也叫浅拷贝),而值拷贝则拷贝的是内容(深拷贝).深拷贝和浅拷贝可以简单理解为:如果一个类拥有资源,当这个类的对象 ...

  2. ASP.NET中的FileUpload文件上传控件的使用

    本篇文章教大家如何将客户端的图片或者文件上传到服务器: 无论是上传图片(.jpg .png .gif等等) 文档(word excel ppt 等等). 第一步:放入以下三个控件 Image控件,Fi ...

  3. 利用IE/FF的不同识别CSS来使用浏览器兼容问题

    区别IE6与FF: background:orange;*background:blue; 区别IE6与IE7: background:green !important;background:blue ...

  4. VC++6.0环境下调试c语言代码的方法和步骤_附图

    1.C语言程序四步开发步骤 (1)编辑.可以用任何一种编辑软件将在纸上编写好的C语言程序输入计算机,并将C语言源程序文件*.c以纯文本文件形式保存在计算机的磁盘上(不能设置字体.字号等). (2)编译 ...

  5. Java [Leetcode 217]Contains Duplicate

    题目描述: Given an array of integers, find if the array contains any duplicates. Your function should re ...

  6. CXF之二(CXF发布webService)

    Apache CXF提供了用于方便地构建和开发WebService的可靠基础架构.它允许创建高性能和可扩展的服务,可以部署在Tomcat和基于spring的轻量级容器中,也可以部署在更高级的服务器上, ...

  7. python 遇到 syntaxerror: non-ascii character '/xd6' in file 我 教你解决 (python问题)(转)

    遇到标题上的问题,按照我的解决广方案来吧 ===================================== (一) 用记事本创建一个文件ChineseTest.py,默认ANSI: s = ...

  8. 《转》GDB中应该知道的几个调试方法

    原文:http://coolshell.cn/articles/3643.html 七.八年前写过一篇<用GDB调试程序>,于是,从那以后,很多朋友在MSN上以及给我发邮件询问我关于GDB ...

  9. 【原】Redis分区

    Redis高级篇 分区 为什么分区? Redis中的分区主要有两个目的: 允许用多台机器的内存存放更大的数据集.如果没有分区,那么你只能存放单台机器内存的最大值的数据集. 允许用多核和多台机器提高计算 ...

  10. C/C++动态分配与释放内存的区别详细解析

    以下是对C与C++中动态分配与释放内存的区别进行了详细的分析介绍,需要的朋友可以过来参考下 1. malloc()函数1.1 malloc的全称是memory allocation,中文叫动态内存分配 ...