简体   繁体   English

webpack 带eslint laoder的通天塔装载机

[英]webpack babel loader with eslint laoder

I'm using webpack babel-loader with es-lint like so我正在使用 webpack babel-loader 和 es-lint 像这样

  {
    test: /\.(js)$/,
    exclude: /node_modules/,
    use: ['babel-loader', 'eslint-loader'],
  },

however in the babel-loader i see on webpack that i have to pass options like so但是在 babel-loader 中,我在 webpack 上看到我必须像这样传递选项

options: {
  presets: ['@babel/preset-env']
}

but since i'm using an array of loaders i can't use this option, or since i'm using eslint with babel loader i don't need this @babel/preset env?但是因为我使用的是加载器数组,所以我不能使用这个选项,或者因为我将 eslint 与 babel 加载器一起使用,所以我不需要这个 @babel/preset env?

You may still want to use @babel/preset even with eslint-loader即使使用eslint-loader ,您可能仍想使用@babel/preset

@babel/preset-env is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). @babel/preset-env是一个智能预设,允许您使用最新的 JavaScript,而无需微观管理目标环境需要哪些语法转换(以及可选的浏览器 polyfill)。 This both makes your life easier and JavaScript bundles smaller!这既让您的生活更轻松,而且 JavaScript 捆绑更小! ( source ) 来源

The eslint-loader will make all code bundled by Webpack syntax checked by eslint (following your eslint config). eslint-loader将使所有由 Webpack 语法捆绑的代码由 eslint 检查(遵循您的 eslint 配置)。

You can either keep babel configuration in a separate file .babelrc.json :您可以将 babel 配置保存在单独的文件.babelrc.json

{
  presets: [
    '@babel/preset-env'
  ]
}

or use the webpack configuration :或使用webpack 配置

use: [{ 
  loader: 'babel-loader',
  options: { presets: ['@babel/preset-env'] },
}, { 
  loader: 'eslint-loader'
}]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM