

This is used in webpack-dev-server internally, however it's available as a separate package to allow more custom setups if desired. It is going to help us reload all of our assets whenever they change. webpack-dev-middleware is a wrapper that will emit files processed by webpack to a server. So with the help of the Webpack dev server, whenever we’re working in a development environment, we don’t have to stop and restart again. I followed their instruction to be able to use a custom template engine like Handlebars or in my case Pug. And once the build ends up bundling, it’s going to reload this for us automatically. I'm currently trying to get Pug templates running with the HTML Webpack Plugin. So when I hit save, the Webpack dev server will detect the change, and it is going to bundle everything up again. Let’s set the text to “Hello from webpack-dev-server”. webpack-typescript-directory-compile-plugin Configure an source directory of typescript files and an output directory for JavaScript files.
WEBPACK DEV SERVER PUG TEMPLATE CODE
We’re going to open index.js, and I will make a small change in our application. Layer-pack Webpack Plugin Allow to glob imports file & directories, build mono repo apps via inheritable source code / npm packages & share webpack configs - Maintainer: Braun Nathanaël. Now let’s go back to our code to ensure that this is working as expected. So let’s go back over to the terminal, so I can say npm run serve, you can see that the same Webpack build steps from before are being performed, and this will tell me that the project is running at localhost:3000. Let’s add another script here called “serve”, and this is going to use. So at this point, I will open up our package.json file. Create an NPM Script to Run the Webpack Dev Server

It will tell the dev server to open your default browser after the server had been started. I’m then going to add another property called “open” and set it to true. We will then add a “contentBase”, which will tell the dev server where to serve the content from, and it will be set to path.join(_dirname, 'dist').Īnd then, we want to specify which port the server should run on. Once this is installed, we can go back to our Webpack config, and we’re going to add another node called “devServer”. Configure Webpack 5 to use webpack-dev-server
WEBPACK DEV SERVER PUG TEMPLATE INSTALL
So I will say npm install -save-dev webpack-dev-server. I’m then going to install the Webpack dev server into dev dependencies. To set up the Webpack dev server, I’m going to navigate to my project directory.


If we want to run the webpack command both in development mode and production mode using our scripts then we must create a separate config object with the common configuration and then based on the arguments of the webpack command we will add diferent rules.
