vue-cli webpack 中全局引入 jquery

1.安装 jQuery

npm install jQuery --save-dev

2.修改 webpack.base.conf.js

方法一

首先加入:

const webpack = require("webpack")

然后在module.exports 对象中加入:

plugins: [
  new webpack.optimize.CommonsChunkPlugin('common.js'),
  new webpack.ProvidePlugin({
    jQuery: "jquery",
    $: "jquery"
  })
]

方法二

先加入:

const webpack = require("webpack")

然后:

resolve: {
  extensions: ['.js', '.vue', '.json'],
  alias: {
    'vue$': 'vue/dist/vue.esm.js',
    '@': resolve('src'),
    'jquery': 'jquery'
  }
},

最后:

plugins: [
  new webpack.ProvidePlugin({
    jQuery: "jquery",
    $: "jquery"
  })
]

.

猜你喜欢

转载自www.cnblogs.com/crazycode2/p/9571244.html