简体   繁体   English

在最小的JavaScript库中使用browserify

[英]Using browserify with a minified JavaScript library

  1. Can a minified JavaScript library be "required" and bundled using Browserify? 是否可以“必需”并使用Browserify将缩小的JavaScript库捆绑在一起? In other words, does Browserify require the JavaScript file to be in source format? 换句话说,Browserify是否要求JavaScript文件为源格式?
  2. If a JavaScript file is not a CommonJS module (does not export anything), can it be bundled using Browserify? 如果JavaScript文件不是CommonJS模块(不导出任何内容),是否可以使用Browserify将其捆绑? In other words, What does require('xyz.js') do if xyz.js is not a CommonJS module. 换句话说,如果xyz.js不是CommonJS模块,则require('xyz.js')做什么。
  1. In case it's properly exporting its properties (eg using exports or module.exports) and loading modules using require() then yes. 如果它正确地导出其属性(例如,使用export或module.exports)并使用require()加载模块,则可以。
  2. Of course it can be bundled, but you can't access its properties/data from the result of the require() call. 当然可以将其捆绑在一起,但是您不能从require()调用的结果中访问其属性/数据。 However if it's using for example the global object for its exports, you can access it after you require the file. 但是,如果它使用例如全局对象进行导出,则可以在需要文件后对其进行访问。

xyz.js: xyz.js:

window.myExport = "hello";

main.js: main.js:

var xyz = require("xyz");
xyz.myExport; // undefined
window.myExport; // "hello"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM