Webpack中ProvidePlugin使用细节

499 阅读1分钟

new Wepack.ProvidePlugin中key要以 '$'开头

  • vue.config.js
const { defineConfig } = require('@vue/cli-service')
const webpack = require('webpack')
module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        gasp:'gsap', // 无效
        $gsap: 'gsap',
        $:'jquery'
      
      })
    ]
  }
})

  • package.json 中关于 eslint的配置
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/vue3-essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "@babel/eslint-parser"
    },
    "rules": {
      "vue/multi-word-component-names": 0
    },
    "globals": {
      "$gsap": true,
      "$": true
    }
  },
```