[Node.js] Broswerify -- 1
Browserify is a tool that brings node.js style development to the browser.
The thing you can see on the node.js cmd line can also be broung up to the broswer.
What you need to do is:
Install the browserify:
npm install -g browserify
Now, for example, you have two javascript file:
entry.js:
/**
* Created by Answer1215 on 12/10/2014.
*/
var test = require('./test'); console.log(test);
test.js:
/**
* Created by Answer1215 on 12/10/2014.
*/
module.exports = ['foo', 'bar', 'tool'];
When you run in the commond line: npm entry.js
you will get the result:
C:\Users\Answer1215\WebstormProjects\angular\commonJSBroswerfiy>node entry
[ 'foo', 'bar', 'tool' ]
But if you run browserfiy:
browserfiy entry.js -o bundle.js
It will create a new file which called bundle.js which minfiy the code, it looks like:
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/**
* Created by Answer1215 on 12/10/2014.
*/
var test = require('./test');
console.log(test);
},{"./test":2}],2:[function(require,module,exports){
/**
* Created by Answer1215 on 12/10/2014.
*/
module.exports = ['foo', 'bar', 'tool'];
},{}]},{},[1]);
Then you can create an html file whcih inclide the bundle.js:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="bundle.js"></script>
</body>
</html>
Check in the broswer:

[Node.js] Broswerify -- 1的更多相关文章
- [Node.js] Broswerify -- 2
Browserify allows you to leverage 10s of thousands of javascript modules available in the Node Packa ...
- node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理
一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...
- 利用Node.js的Net模块实现一个命令行多人聊天室
1.net模块基本API 要使用Node.js的net模块实现一个命令行聊天室,就必须先了解NET模块的API使用.NET模块API分为两大类:Server和Socket类.工厂方法. Server类 ...
- Node.js:进程、子进程与cluster多核处理模块
1.process对象 process对象就是处理与进程相关信息的全局对象,不需要require引用,且是EventEmitter的实例. 获取进程信息 process对象提供了很多的API来获取当前 ...
- Node.js:理解stream
Stream在node.js中是一个抽象的接口,基于EventEmitter,也是一种Buffer的高级封装,用来处理流数据.流模块便是提供各种API让我们可以很简单的使用Stream. 流分为四种类 ...
- Node.js:Buffer浅谈
Javascript在客户端对于unicode编码的数据操作支持非常友好,但是对二进制数据的处理就不尽人意.Node.js为了能够处理二进制数据或非unicode编码的数据,便设计了Buffer类,该 ...
- node.js学习(二)--Node.js控制台(REPL)&&Node.js的基础和语法
1.1.2 Node.js控制台(REPL) Node.js也有自己的虚拟的运行环境:REPL. 我们可以使用它来执行任何的Node.js或者javascript代码.还可以引入模块和使用文件系统. ...
- Node.js npm 详解
一.npm简介 安装npm请阅读我之前的文章Hello Node中npm安装那一部分,不过只介绍了linux平台,如果是其它平台,有前辈写了更加详细的介绍. npm的全称:Node Package M ...
- Node.js入门(一)
一.Node.js本质上是js的运行环境. 二.可以解析js代码(没有浏览器安全级的限制): 提供系统级的API:1.文件的读写 2.进程的管理 3.网络通信 三.可以关注的四个网站: 1.https ...
随机推荐
- python程序中自启动appium服务
普通启动Appium服务方法: 打开cmd,运行命令: #>appium -a 127.0.0.1 -p 4723 当程序输出如上图信息的时候,表示appium启动成功,此时便可以运行 ...
- 数往知来 JavaScript<十三>
一.javaScript 语法:大小写敏感,弱类型(所有类型都用var进行引导.声明) 写在<script></script>标签里 不可以放在title里 var num= ...
- Linux中的.emacs文件
刚开始的时候在Windows下使用emacs,那个时候配置 .emacs文件直接去C盘里\Users\(username)\AppData\Roaming 路径下查找就可以了(最开始的时候可以打开em ...
- 谈layout_gravity和gravity的用法
相信对于Android的初学者来说,大家都曾经被layout里这两个极其相似的属性迷惑过. 简单使用一下搜索工具,我们就不难找到下面这样的答案: layout_gravity 表示组件自身在父组件 ...
- MATLAB图像处理工具箱
下列表格中除了个别函数外,其余函数都是图像处理工具箱提供的关于图像处理的函数,现摘录到此以备查找. 表1 图像显示 函数名 功能说明 函数名 功能说明 colorbar 颜色条显示 montage 按 ...
- python日志模块logging
python日志模块logging 1. 基础用法 python提供了一个标准的日志接口,就是logging模块.日志级别有DEBUG.INFO.WARNING.ERROR.CRITICAL五种( ...
- c++ struct 使用
typedef与结构结合使用 typedef struct tagMyStruct{ int iNum; long lLength;} MyStruct; 这语句实际上完成两个操作: 1) 定义一 ...
- 《The Google File System》论文阅读笔记——GFS设计原理
一.设计预期 设计预期往往针对系统的应用场景,是系统在不同选择间做balance的重要依据,对于理解GFS在系统设计时为何做出现有的决策至关重要.所以我们应重点关注: 失效是常态 主要针对大文件 读操 ...
- js_sl 延迟菜单
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 【转】Java transient关键字
Volatile修饰的成员变量在每次被线程访问时,都强迫从主内存中重读该成员变量的值.而且,当成员变量发生变化时,强迫线程将变化值回写到主内存.这样在任何时刻,两个不同的线程总是看到某个成员变量的同一 ...