M
M
Maverick17user2018-12-22 19:16:49
Web development
Maverick17user, 2018-12-22 19:16:49

How to set multiple loaders for one use in Webpack4 configuration?

Trying Webpack(4.28.1) for the first time.
There is this webpack.config.js code:

const path = require('path');

module.exports = {
    entry: __dirname + '/src/components/App.jsx',
    output: {
        publicPath: 'dest/js',
        path: path.resolve(__dirname, '/dest/js'),
        filename: 'bundle.js'
    },
    devtool: '#sourcemap',
    module: {
        rules: [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: 'react-hot-loader'
                    },
                    {
                        loader: 'babel-loader',
                        options: {
                            presets: ['@babel/env', '@babel/react']
                        }
                    }
                ]
            }
        ]
    }
}

I need the functionality of react-hot-loader and babel-loader, but it's not clear how to properly declare two loaders in one use.
When starting web-dev-server, it gives an error:
5c1e62d64a5bc044168533.png
How to solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Troinov, 2018-12-22
@tot0ro

The error says that an invalid loader is being used, try demolishing node_modules and reinstalling it, or installing react-hot-loader with a lower version.
This is how create-react-app does it:
https://github.com/facebook/create-react-app/blob/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question