您可以防止用的ESLint和no-undef rule
帮助不确定的变量构建包。
准备包该解决方案
npm install eslint eslint-loader eslint-friendly-formatter --save-dev
您应该配置.eslintrc
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"rules": {
"no-undef": 2 // <-- ERROR on not defined variables
}
}
在你webpack.config.js
您必须添加此行来支持ESLint掉毛
module.exports = {
loaders: [
{
test: /\.js$/,
loader: 'eslint-loader',
exclude: /(node_modules|bower_components)/
},
// ...
],
eslint: {
failOnError: true, // block build on non passed linting
configFile: '.eslintrc', // path to your .eslintrc
formatter: require('eslint-friendly-formatter') // better error report
},
// ...
};
这CONFIGS给你这种错误
ERROR in ./src/example.js
Module build failed: Error: Module failed because of a eslint error.
✘ http://eslint.org/docs/rules/no-undef 'bar' is not defined
/yourpath/src/example.js:2:11
var foo = bar;
^
✘ 1 problem (1 error, 0 warnings)
你可以尝试用ESLint没有民主基金的规则:http://eslint.org/docs/rules/no-undef – Everettss
可以很容易地实现与ESLint你问什么,但不''使用strict''条件(你不能指定ESLint规则取决于是否使用'strict strict')。 – Everettss
完美。我已经在使用eslint,但由于某种原因,从来没有想过要检查eslint规则。 – chrisp