【发布时间】:2016-02-29 22:55:44
【问题描述】:
我用 npm 安装了 bootstrap 4。我目前正在使用反应库。我正在为 es2015 做出明智的 babel 并做出反应。也使用 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 ]
}
【问题讨论】:
-
您的 jQuery 加载器与文档略有不同 -
{ test: /bootstrap\/dist\/js\/umd\//, loader: 'imports?jQuery=jquery' },可能是它? -
@Harangue 试过了,但没有用。但是发现这篇文章确实有帮助http://stackoverflow.com/questions/28969861/managing-jquery-plugin-dependency-in-webpack
标签: node.js twitter-bootstrap npm webpack