我用npm安装了bootstrap 4。我目前正在使用反应库。我正在为es2015发出狡猾的声音并做出反应。也使用webpack。在控制台我得到关于jQuery的以下错误,来自文件transition.js:
Uncaught ReferenceError: jQuery is not defined transition.js
这是webpack配置:
const webpack = require('webpack');
const path = require('path');
const autoprefixer = require('autoprefixer');
module.exports = {
entry: [
"./client/main.js",
"bootstrap-loader",
],
output: {
path: './public',
filename: "bundle.js",
publicPath: '/'
},
devServer: {
inline: true,
contentBase: './public'
},
module: {
loaders: [
{
test:/\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['react', 'es2015']
}
},
{ test: /\.css$/, loaders: [ 'style', 'css', 'postcss' ] },
{ test: /\.scss$/, loaders: [ 'style', 'css', 'postcss', 'sass' ] },
{ test: /bootstrap\/dist\/js\/umd\//, loader: 'imports?jQuery=jquery!./file.js' },
{ test: /\.(woff2?|ttf|eot|svg)$/, loader: 'url?limit=10000' },
]
},
postcss: [ autoprefixer ]
}
答案 0 :(得分:0)
问题是我需要在web pack config
上使用他的后续行var webpack = require('webpack');
....
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
],
在以下帖子中找到答案:Managing jQuery plugin dependency in webpack