前人栽树,后人乘凉,以下为学习笔记
简介
Browserify是一个供浏览器环境使用的模块打包工具,像在node环境一样,也是通过require(‘modules’)来组织模块之间的引用和依赖,既可以引用npm中的模块,也可以引用自己写的模块,然后打包成js文件,再在页面中通过<script>标签加载。
准备
npm install -g browserify
使用
// hello.js
module.exports = 'Hello world';
// entry.js
var msg = require('./hello.js');
console.log("MSG:", msg);
browserify entry.js -o bundle.js
// --outfile, -o 指定打包后的输出文件 ; 如果不指定,将输到stdout,比如shell
指南
- 官方 官方文档
- 中文: Browserify使用指南(转)