码迷,mamicode.com
首页 > 其他好文 > 详细

browserify的standalone的含义

时间:2017-01-22 09:40:13      阅读:560      评论:0      收藏:0      [点我收藏+]

标签:undefined   define   sys   blog   host   前端   type   one   dal   

白话:就像Jquery的$, 把你打包后的函数挂在window下你指定的名字下

废话:白话看不懂,就看下面的废话,你不得不花更多时间理解
--standalone AAA的含义
$ browserify foo.js --standalone AAA > bundle.js
This command will export the contents of foo.js under the external module name AAA. If a module system is detected in the host environment, it will be used. Otherwise a window global named AAA will be exported.
当在主机上检测到module system时,直接使用module system。没有检测到module system时,使用window global named AAA

在浏览器中时,window.AAA下挂的是你的module.exports
而在node环境下,AAA不起作用
看下面的代码

    if (typeof exports === "object" && typeof module !== "undefined") {
        module.exports = f()
    } else if (typeof define === "function" && define.amd) {
        define([], f)
    } else {
        var g;
        if (typeof window !== "undefined") {
            g = window
        } else if (typeof global !== "undefined") {
            g = global
        } else if (typeof self !== "undefined") {
            g = self
        } else {
            g = this
        }
        g.AAA = f()
    }

所以说standalone其实是一种模式。这么重要的功能设计成一个不起眼的选项,

名字还这么长,这么怪。可以说设计的缺点。

 

顺便聊下bare的含义
--bare
假设在程序中用了Buffer(Buffer在nodejs中是一个内建的类)的是时候。browserify遇到Buffer,会在bundle中添加Buffer类的前端实现。然而,--bare会阻止它添加Buffer类。这样,Buffer在node中是什么就是什么,程序是原汁原味的,原来是什么,现在还是什么,这也是为什么叫bare的原因。

browserify的standalone的含义

标签:undefined   define   sys   blog   host   前端   type   one   dal   

原文地址:http://www.cnblogs.com/thus/p/6339387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!