Configuring NPM and Webpack
  • 23 Feb 2024
  • 1 Minute to read
  • Dark
    Light
  • PDF

Configuring NPM and Webpack

  • Dark
    Light
  • PDF

Article summary

If you are using NPM and Webpack, you will need to configure them to move the static HTML templates into the directory where files are served.

Procedure

  1. Open package.json from the root project directory and add copy-webpack-plugin as a development dependency by running:

    // package.json line #13
    // ...
    "devDependencies": {
      "copy-webpack-plugin": "^4.6.0",
      "css-loader": "^1.0.1",
    // ...
  2. Open webpack.config.js, import copy-webpack-pluginand configure the static elements to be copied into the serving directory by running:

    // webpack.config.js line #1
    const path = require('path');
    const CopyWebpackPlugin = require('copy-webpack-plugin');
    const HtmlWebpackPlugin = require('html-webpack-plugin');
    // webpack.config.js line #32
    plugins: [
      new HtmlWebpackPlugin({
        template: "src/index.html",
        favicon: 'src/image/favicon.ico'
      }),
    
      // Configure plugin to copy static elements
      new CopyWebpackPlugin([
        {
          from: 'src/lorem-ipsum-formatted.html',
          to: ''
        },
        {
          from: 'src/image/ipse-dixit.png',
          to: ''
        },
        {
          from: 'src/image/greek-statue-face.png',
          to: ''
        }])
    ],
    // ...


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.