【问题标题】:Jquery error installing bootstrap 4 with npm使用 npm 安装引导程序 4 时出现 Jquery 错误
【发布时间】: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


【解决方案1】:

问题是我需要在 web pack 配置中使用他以下行

var webpack = require('webpack');
....
plugins: [
    new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery"
    })
],

在以下帖子中找到答案:Managing jQuery plugin dependency in webpack

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多