Webpack无法识别光滑

时间:2019-05-19 19:06:33

标签: jquery webpack slick

我有一个django项目,我也在使用webpack。我在全球范围内安装了jquery,我可以单独使用它而不会出现问题,但是我似乎无法导入光滑的文件。我试过使用CDN并也在全局安装slick,但是我总是会收到此错误:

Uncaught ReferenceError: jQuery is not defined
    at slick.min.js:1
    at slick.min.js:1
(anonymous) @ slick.min.js:1
(anonymous) @ slick.min.js:1

这是我的webpack.base.js(我还创建了一个用于生产,另一个创建用于开发):

var path = require('path');
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');

module.exports = [{
  entry: './assets/js/script',
  output: {},
  module: {
    rules: [
      { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader'},
    ],
  },

  resolve: {
    modules: ['node_modules', 'bower_components', path.resolve(__dirname, 'assets/js/'),],
    extensions: ['.js', '.jsx']
  },
  plugins: [
    new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
    }),
]
},{
  context: __dirname,
  entry: './assets/css/style.scss',
  output: {},
  module: {
    rules: [
      {
        test: /\.css$/,
        loaders: [
          'style-loader',
          'css-loader',
        ],
      },
      {
        test: /\.scss$/,
        loaders: [
          'style-loader',
          'css-loader',
          'sass-loader',
        ],
      },
      {
        test: /\.(svg)(\?v=\d+\.\d+\.\d+)?$/,
        loader: 'url-loader?limit=100000',
      },
      {
        test: /\.(jpg|png)?$/,
        loaders: [
          'file-loader?name=i-[hash].[ext]',
        ],
      },
    ]
  }
}]

在我的js文件中,使用import $ from 'jquery'; import 'slick-carousel';

似乎没有什么区别

0 个答案:

没有答案