问题
- 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.
回答1:
- 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"
来源:https://stackoverflow.com/questions/24874139/using-browserify-with-a-minified-javascript-library