简体   繁体   中英

webpack babel loader with eslint laoder

I'm using webpack babel-loader with es-lint like so

  {
    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

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?

You may still want to use @babel/preset even with eslint-loader

@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). This both makes your life easier and JavaScript bundles smaller! ( source )

The eslint-loader will make all code bundled by Webpack syntax checked by eslint (following your eslint config).

You can either keep babel configuration in a separate file .babelrc.json :

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

or use the webpack configuration :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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