Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write webpack.config.js when set more param?

I want to handle my jsx code, so I write webpakc.config.js like this:

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

But it didn't handle my jsx code and throw an error like this: The error threw in terminal

By Google I find I need to add presets['react'] to my config file. So I update config like this:

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

But it threw another error: A new error threw after update config file

I am a fresher in webpack, What should I do?

like image 465
wen Avatar asked Nov 11 '15 00:11

wen


1 Answers

The first error seems to be a syntax error in your JSX. Difficult to tell what it is from the comment. Try posting the JSX file contents.

About the second error: Query params for a specific loader needn't necessarily be specified as a JSON object. You can specify them as a query string adjoining the loader name as well. Eg. the same config can be expressed with this line:

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

Of course, you'll need to remove the query JSON once you use the above. More info here: https://webpack.github.io/docs/using-loaders.html#query-parameters

like image 180
akaashanky Avatar answered Sep 28 '22 07:09

akaashanky