Using browserify with a minified JavaScript library

。_饼干妹妹 提交于 2019-12-13 07:18:28

问题


  1. 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?
  2. 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.

回答1:


  1. In case it's properly exporting its properties (e.g. using exports or module.exports) and loading modules using require() then yes.
  2. 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"


来源:https://stackoverflow.com/questions/24874139/using-browserify-with-a-minified-javascript-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!