分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

html-webpack-plugin插件 根据模板生成多页面

发布时间:2023-09-06 01:10责任编辑:蔡小小关键词:webpack

1、项目目录结构为:

2、webpack.config.js配置文件为:

var htmlWebpackPlugin = require(‘html-webpack-plugin‘);module.exports = { ???//打包入口 ???entry: { ???????main: ‘./src/js/main.js‘, ???????a: ‘./src/js/a.js‘, ???????b: ‘./src/js/b.js‘, ???????c: ‘./src/js/c.js‘ ???}, ???//打包后的文件 ???output: { ???????//不加__dirname 会报错 ???????path: __dirname + ‘/dist‘, ???????//注意:使用[name]确保每个文件名都不重复 ???????filename: ‘js/[name]-[chunkhash].js‘, ???????//线上地址配置 ???????publicPath:‘http://cdn.com/‘ ???}, ???plugins: [ ???????new htmlWebpackPlugin({ ???????????template: ‘index.html‘, ???????????filename: ‘a.html‘, ???????????title: ‘this is a.html‘, ???????????//增加指定的chunks ???????????chunks:[‘main‘,‘a‘] ???????}), ???????new htmlWebpackPlugin({ ???????????template: ‘index.html‘, ???????????filename: ‘b.html‘, ???????????title: ‘this is b.html‘, ???????????//增加指定的chunks ???????????chunks:[‘main‘,‘b‘] ???????}), ???????new htmlWebpackPlugin({ ???????????template: ‘index.html‘, ???????????filename: ‘c.html‘, ???????????title: ‘this is c.html‘, ???????????//增加指定的chunks ???????????chunks:[‘main‘,‘c‘] ???????}) ???]}

3、执行命令:

npm run webpack

4.编译:

html-webpack-plugin插件 根据模板生成多页面

原文地址:http://www.cnblogs.com/mengfangui/p/7514270.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved