玖叶教程网

前端编程开发入门

webpack5打包html(webpack5打包图片)

打包html需要用到一个插件html-webapck-plugin。

npm i html-webpack-plugin -D

package.json需要的开发依赖如下:

{
  "name": "wpk5-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "html-webpack-plugin": "^5.3.1",
    "webpack": "^5.28.0",
    "webpack-cli": "^4.5.0"
  }
}

webpack.config.js的配置如下:

const { resolve } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
    entry: './src/main.js',
    output: {
        filename: 'bundle.js',
        path: resolve(__dirname, 'dist')
    },
    module: {
        rules: []
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/assets/index.html',
            hash: true,
            filename: 'index.html',
            favicon: './src/assets/favicon.ico'
        })
    ],
    mode: 'development'
}

代码仓库:https://gitee.com/seimin/xiaoming2qianduan-webpack5/tree/v5.1/

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言