在最小的JavaScript库中使用browserify [英] Using browserify with a minified JavaScript library
本文介绍了在最小的JavaScript库中使用browserify的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 是否可以必需并使用Browserify将缩小的JavaScript库捆绑在一起?换句话说,Browserify是否要求JavaScript文件为源格式?
- 如果JavaScript文件不是CommonJS模块(不导出任何内容),是否可以使用Browserify将其捆绑?换句话说,如果xyz.js不是CommonJS模块,
require('xyz.js')
会做什么。
- Can a minified JavaScript library be "required" and bundled using Browserify? In other words, does Browserify require the JavaScript file to be in source format?
- If a JavaScript file is not a CommonJS module (does not export anything), can it be bundled using Browserify? In other words, What does
require('xyz.js')
do if xyz.js is not a CommonJS module.
推荐答案
- 如果适当地导出其属性(例如,使用export或module.exports)并使用<$加载模块c $ c> require()然后是。
- 当然可以将其捆绑在一起,但是您不能从结果中访问其属性/数据。
require()
调用。但是,如果它使用例如全局对象进行导出,则可以在需要文件后访问它。
- In case it's properly exporting its properties (e.g. using exports or module.exports) and loading modules using
require()
then yes. - Of course it can be bundled, but you can't access its properties/data from the result of the
require()
call. However if it's using for example the global object for its exports, you can access it after you require the file.
xyz.js:
window.myExport = "hello";
main.js:
var xyz = require("xyz");
xyz.myExport; // undefined
window.myExport; // "hello"
这篇关于在最小的JavaScript库中使用browserify的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文