【问题标题】:vue cli 3 - ProvidePlugin doesn't work (vue.config.js)vue cli 3 - ProvidePlugin 不起作用(vue.config.js)
【发布时间】:2019-03-25 15:02:35
【问题描述】:

我正在尝试添加不适用于 Vue-cli 3webpack.ProvidePlugin。 我还尝试将lodash 设置为全局导入(因此我不必在每个商店模块中导入它)。

vue.config

const webpack = require("webpack");

module.exports = {
  configureWebpack: {
    plugins: [new webpack.ProvidePlugin({ _: "lodash" })]
  }
};

构建错误:

Module Warning (from ./node_modules/eslint-loader/index.js):
error: '_' is not defined (no-undef) at src/store/modules/templates.js:24:10:
  22 | export default Object.assign({}, base, {
  23 |   namespaced: true,
> 24 |   state: _.cloneDeep(initialState),
     |          ^
  25 |   mutations: {
  26 |     addTemplate(state, template) {
  27 |       if (!template) throw new Error("template is missing");

我在将行添加到vue.config 后构建了项目,他们给了我上述错误。

【问题讨论】:

    标签: webpack-4 vue-cli-3


    【解决方案1】:

    问题似乎不在于 Vue CLI,而在于 eslint。有关类似问题,请参阅此问题(只需将 d3 替换为 _):Webpack not including ProvidePlugins

    简而言之,将其添加到您的 eslint 配置(通常在 .eslintrc.js 中找到)应该可以使其工作:

    "globals": {
       "_": true
    }
    

    【讨论】:

      猜你喜欢
      • 2020-02-08
      • 2018-12-05
      • 2019-04-08
      • 2021-08-27
      • 2019-12-17
      • 2022-01-14
      • 2020-03-12
      • 1970-01-01
      相关资源
      最近更新 更多