Webpack - webpack-dev-server two configs

1.4k Views Asked by At

I have a project, which consists of two parts.. an admin environment and a part of web for regular users. Each part has another assets, so I have two configurations for webpack. First is named webpack-front.config.js and second is named webpack-admin.config.js.

My structure:

├─┬ dist
│ ├── front.bundle.js 
│ └── admin.bundle.js
|
├─┬ src
│ ├─┬ front
| | └── index.js
│ └─┬ admin
|   └── index.js

Problem starts, when I try to run "webpack-dev-server --open". Npm prints:

> webpack-dev-server --open

No configuration file found and no entry configured via CLI option.
When using the CLI you need to provide at least two arguments: entry and output.
A configuration file could be named 'webpack.config.js' in the current directory.
Use --help to display the CLI options.
npm ERR! code ELIFECYCLE
npm ERR! errno 255
npm ERR! [email protected] start: `webpack-dev-server --open`
npm ERR! Exit status 255
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2017-12-04T14_16_35_084Z-debug.log

This problem occurs because my configs are not named "webpack.config.js". Is there any way, how to run webpack-dev-server with another config or with both configs at once?

2

There are 2 best solutions below

0
On

You can use the config option to specify your custom config file.

> webpack-dev-server --config /home/user/project/path_to_config_file
0
On

Yes there is. To specify a configuration file, use the --config flag. So your command would look like

webpack-dev-server --open --config webpack-front.config.js

Unfortunately, I was only able to find reference to it in the webpack 1 docs. https://webpack.github.io/docs/webpack-dev-server.html#webpack-dev-server-cli