我有一个问题,我包含一个jQuery插件(jquery.jplayer.js
),webpack正在同一个文件中加载该插件的依赖项,在本例中是jQuery。我想要通过CDN提供jQuery,所以很明显我也不想在本地加载jQuery。我已将其缩小到这行代码define(['jquery'], factory); // jQuery Switch
。
如何告诉webpack不包含它在.js
文件中找到的依赖项?
var debug = process.env.NODE_ENV !== "production";
var webpack = require("webpack");
var path = require("path");
module.exports = {
context: __dirname,
devtool: debug ? "inline-sourcemap" : null,
entry: {
app: "./wwwroot/js/app.js",
lib: "./wwwroot/lib/jPlayer/dist/jplayer/jquery.jplayer.js"
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
query: {
presets: ["react", "es2015", "stage-0"],
plugins: ["react-html-attrs", "transform-class-properties", "transform-decorators-legacy"],
}
}
]
},
output: {
path: "./wwwroot/build/",
filename: "[name].js"
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false })
]
};
答案 0 :(得分:1)
此代码将jQuery排除在捆绑之外:
externals: {
"jquery": "jQuery"
},
答案 1 :(得分:0)
您可以在webpack中使用提供插件
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})