问题:webpack插件DefinePlugin定义的全局变量APP_VERSION编译时候提示'APP_VERSION' is not defined。导致项目运行。
vue.config.js中配置如:
plugins:[
new webpack.DefinePlugin({
APP_VERSION: `"${require('./package.json').version}"`
})
]
解决:.eslintrc.js中添加并配置globals属性:
module.exports = {
root: true,
env: {
node: true
},
"globals": {
"APP_VERSION": true
},
'extends': [
'plugin:vue/strongly-recommended',
'@vue/standard'
],
rules: {
'no-console': 'off',
}
}
另一种解决方式:在全局变量APP_VERSION的上一行位置添加/* eslint-disable no-undef */,
也能够解除警告,但是其他的未添加入globals的全局变量也会被解除,例如这里的GIT_HASH