To start the Webpack development server, use the command webpack dev-server --inline --progress --port 9090
.
%%
bash
webpack - dev - server--
inline--
progress--
port
9090
typescript
// Import the required module from the webpack package
import webpack from 'webpack';
// Define the configuration for the webpack-dev-server
const webpackConfig = {
// Define the module for the dev-server
devServer: {
// Display the inline compiler output
inline: true,
// Display the progress bar
progress: true,
// Set the port for the development server
port: 9090,
},
};
// Check if the --mode argument is provided
if (process.argv.includes('--mode')) {
// Set the mode for the webpack configuration
webpackConfig.mode = process.argv[process.argv.indexOf('--mode') + 1];
}
// Create a new instance of the webpack-dev-server
const devServer = webpack.createDevServer(webpackConfig);
// Start the development server
devServer.start(() => {
console.log('Webpack development server started on port 9090');
});
Command Breakdown
webpack
: The command to start the Webpack development server.dev-server
: The mode to run the server in, which is development mode.--inline
: Enables inline mode for the development server.--progress
: Enables progress output for the development server.port 9090
: Specifies the port number for the development server to run on.