[Whole Web] [Node.js] [Browserify] [Grunt] Automation task with grunt-browserify & grunt-contrib-watch
2023-09-14 08:59:21 时间
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
相关文章
- Robynn&Kendy《海阔天空》
- html如何只刷新页面指定,js控制页面刷新 JS刷新当前页面的几种方法总结
- 第2章 WEB02-CSS&JS篇-视频教程-第一部分
- uptimerobot服务监控、通知 & 手机APP监控
- 零零信安-D&D数据泄露报警日报【第28期】
- 谷粒学院day0&day1——项目介绍与mybatis plus入门
- JS获取当前年份_js获取当前时间年月日
- Vue.js – 引入外部 JS 文件
- Linux系统自带Python2&yum的卸载及重装
- JS设置定时器_js设置定时器
- js事件循环与macroµ任务队列
- 应用于高速收发模块的并行光学&WDM波分光学技术
- JS模块化—CJS&AMD&CMD&ES6-前端面试知识点查漏补缺_2023-03-13
- JS &&、||、!逻辑运算符及用法
- Node.js连接MSSQL数据库的操作指南(node 链接mssql)
- JS在Oracle中的应用(js如何oracle)
- 从前端JS里请求Redis资源,搭建高性能应用(前端js请求redis)
- 使用Oracle和JS开发新一代应用仿真世界(oracle js)
- 用js怎么把&字符换成"&:"
- 探讨Oracle中的&号问题