eslint使用

需引入插件:eslint-loader eslint __eslint-config-airbnb-base eslint-plugin-import

  1. const { resolve } = require('path')
  2. const HtmlWebpackPlugin = require("html-webpack-plugin");
  3. module.exports = {
  4. entry: './src/js/index.js',
  5. output: {
  6. filename: 'js/built.js',
  7. path: resolve(__dirname, 'build')
  8. },
  9. module: {
  10. rules: [
  11. /**
  12. * 语法检查:eslint-loader eslint
  13. * 注意:只检查源代码,第三方库是不检查的
  14. * 设置检查规则:
  15. * package.json中eslintConfig中设置
  16. *
  17. * "eslintConfig":{
  18. "extends":"airbnb-base"
  19. }
  20. *
  21. * airbnb --> eslint-config-airbnb-base eslint-plugin-import eslint
  22. */
  23. {
  24. test: /\.js$/,
  25. exclude: /node_modules/,
  26. loader: 'eslint-loader',
  27. options: {
  28. //自动修复eslint的错误
  29. fix: true
  30. }
  31. }
  32. ]
  33. },
  34. plugins: [
  35. new HtmlWebpackPlugin({
  36. template: './src/index.html'
  37. })
  38. ],
  39. mode: 'development'
  40. }

package.json配置

  1. "eslintConfig":{
  2. "extends":"airbnb-base"
  3. }