0
我有以下的WebPack配置:的WebPack加載失敗骨幹沒有jQuery的
module.exports = {
entry: "./league/index.ts",
output: {
path: "./",
filename: "bundle.js"
},
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: ["", ".ts", ".js"]
},
module: {
loaders: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.ts?$/, loader: "ts-loader" }
]
}
};
當我運行webpack
,我得到這個錯誤(實際項目路徑與PROJECT_PATH
取代了隱私):
ERROR in ./~/backbone/backbone.js
Module not found: Error: Cannot resolve module 'jquery' in PROJECT_PATH\node_modules\backbone
@ ./~/backbone/backbone.js 17:4-21:6
原因是這個代碼在backbone.js
:
// Set up Backbone appropriately for the environment. Start with AMD.
if (typeof define === 'function' && define.amd) {
define(['underscore', 'jquery', 'exports'], function(_, $, exports) {
// Export global even in AMD case in case this script is loaded with
// others that may still expect a global Backbone.
root.Backbone = factory(root, exports, _, $);
});
// Next for Node.js or CommonJS. jQuery may not be needed as a module.
} else if (typeof exports !== 'undefined') {
var _ = require('underscore'), $;
try { $ = require('jquery'); } catch (e) {}
factory(root, exports, _, $);
// Finally, as a browser global.
}
jQuery不是我需要的依賴關係,但webpack
正在解釋require
調用,因爲我需要它。