browserify --standalone projzh index.js | uglifyjs --output index.min.js
我们使用CMD写的模块需要使用browserify 打包成AMD模块语法给浏览器使用,
--standalone projzh
的意思是把这个模块命名成projzh
,挂载在window
作用域下面
下面是自动生成的代码:
if (typeof exports === "object" && typeof module !== "undefined") {//CMD
module.exports = f()
} else if (typeof define === "function" && define.amd) {//AMD
define([], f)
} else {
var g;
if (typeof window !== "undefined") {//挂载到浏览器window对象
g = window
} else if (typeof global !== "undefined") {//挂载到node 的global 对象
g = global
} else if (typeof self !== "undefined") {//挂载到 webWorker的self 对象
g = self
} else {//挂载到上下文this对象中
g = this
}
g.projzh = f()
}
package.json
"scripts": {
"bundle": "browserify --standalone projzh index.js | uglifyjs --output index.min.js",
"prepublish": "npm run bundle",
"pretest": "eslint . --ignore-pattern *.min.js",
"test": "lab --leaks test"
},
网友评论