Configuring NPM and Webpack
- 23 Feb 2024
- 1 Minute to read
- Print
- DarkLight
- PDF
Configuring NPM and Webpack
- Updated on 23 Feb 2024
- 1 Minute to read
- Print
- DarkLight
- PDF
Article summary
Did you find this summary helpful?
Thank you for your feedback
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
Open
package.json
from the root project directory and addcopy-webpack-plugin
as a development dependency by running:// package.json line #13 // ... "devDependencies": { "copy-webpack-plugin": "^4.6.0", "css-loader": "^1.0.1", // ...
Open
webpack.config.js
, importcopy-webpack-plugin
, and 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?