js几个html合成一个文件夹,webpack 打包之html多个打包 -2

1:确保自己的电脑已经安装了node和Git软件

2:自己在盘里随便创建一个文件夹一般为英文(也就是你自己的项目名称)

3:在新创建好的文件夹里面右键点击调出git指令窗口在窗口里面输入如下指令:

1:npm install webpack -g

2:  npm install webpack-cli -g

3: npm init -y

4: npm install webpack --save-dev

5  npm install html-webpack-plugin    (html编译插件)

6:npm install clean-webpack-plugin

5:把项目拖进编辑器

6新建一个src文件夹  和webpack.config.js

49fabf69d27e30efea7fabb312b8e88b.png

7:webpack.config.js内容配置如下:

const path = require("path");

const WebpackHtmlPlugin = require('html-webpack-plugin'); //导入html打包插件

const clear= require("clean-webpack-plugin"); //导入清除dist插件 不用手动每次去删除dist文件

// 夹

module.exports = {

entry: {

index1: './src/index1.js',

index2: './src/index2.js'

},

output: {

path: path.resolve(__dirname, "dist"),

filename: "[name].js"

},

plugins: [

new WebpackHtmlPlugin({

minify: {

collapseWhitespace: true, //清除空格

removeAttributeQuotes: true, //清除多余引号

removeComments: true //删除注释

},

title: "hello",

template: "./src/index.html",

chunks: ['index'],

filename: "index.html"

}),

new WebpackHtmlPlugin({

minify: {

collapseWhitespace: true, //清除空格

removeAttributeQuotes: true, //清除多余引号

removeComments: true //删除注释

},

title: "hello2", //打包成功后的html名字

template: "./src/index2.html",//要打包的文件路径

chunks: ['index2'],

filename: "index2.html" //要打包的文件名称

}),

new clear() //导入模块清除dist插件 不用手动每次去删除dist文件

// 夹

]

}

8:package.json  scripts配置如下:

"scripts": {

"build": "webpack --mode production" //production生产环境 development开发环境

},

9:要打包的html  title处需配置

10:执行命令进行打包 npm run build

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值