How to write webpack.config.js when setting more parameters?

I want to process my jsx code, so I write webpakc.config.js as follows:

{ test: /\.js$/, loaders: ['react-hot', 'babel-loader?presets[]=es2015'], exclude: /node_modules/ } 

But he did not process my jsx code and threw an error: Error in the terminal

Google, it seems to me, I need to add presets['react'] to my configuration file. Therefore, I update the configuration as follows:

 { test: /\.js$/, loaders: ['react-hot', 'babel'], query: { presets: ['react', 'es2015'] }, exclude: /node_modules/ } 

But this is another mistake: A new error occurred after the update configuration file

I am better at webpack, what should I do?

+7
webpack config react-jsx
source share
1 answer

The first error seems to be a syntax error in your JSX. It is hard to say that this is from a comment. Try publishing the contents of the JSX file.

About the second error: Request parameters for a specific loader need not be specified as a JSON object. You can specify them as a query string adjacent to the bootloader name. For example. the same configuration can be expressed using this line:

 loaders: ['react-hot', 'babel?presets[]=react,presets[]=es2015'] 

Of course, you will need to remove the JSON request after using the above. More details here: https://webpack.imtqy.com/docs/using-loaders.html#query-parameters

+13
source share

All Articles