Reputation: 23
Below is the code used in server.js file in a react js application. But I am not able to understand the syntax of this statement. Here after require('webpack-dev-middleware') there is no .
used and suddenly another bracket started with some arguments. Can someone please explain how is it working?
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
Upvotes: 1
Views: 66
Reputation: 24660
require('webpack-dev-middleware')
is returning a function. This is just a shortened version of this
const webpackMiddleware = require('webpack-dev-middleware');
const webpackCompiler = webpackMiddleware(compiler, {
noInfo: true,
publicPath: config.output.publicPath
});
app.use(webpackCompiler);
Upvotes: 1
Reputation: 2975
require('webpack-dev-middleware')
returns a function.
The second set of brackets contain arguments to be passed to this returned function.
Upvotes: 1
Reputation: 45121
Simply extract parts of this expression as separate variables
const createWebpackMiddleware = require('webpack-dev-middleware')
const options = {
noInfo: true,
publicPath: config.output.publicPath
}
const webpackMiddleware = createWebpackMiddleware(compiler, options)
app.use(webpackMiddleware );
Upvotes: 0