webpack的基本配置文件webpack.config.js
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20var htmlWebpackPlugin = require('html-webpack-plugin'); //加载插件生成html文件 module.exports = { entry:{ main: './src/script/main.js', a: './src/script/a.js' }, output: { filename: './dist/js/[name]-[hash].js', }, plugins: [ new htmlWebpackPlugin({ filename: './dist/index-[hash].html', template: 'index.html', inject: 'head', //js文件引用位置 title: 'webpack is good', //title内容自定义 date: new Date() }) ] }
模板页面index.html
复制代码
1
2
3
4
5
6
7
8
9
10<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title><%= htmlWebpackPlugin.options.title %></title> //引用配置文件自定义标题 </head> <body> <%= htmlWebpackPlugin.options.date %> //引用时间 </body> </html>
自动生成的index-[hash].html
复制代码
1
2
3
4
5
6
7
8
9
10<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>webpack is good</title> <script type="text/javascript" src=".././dist/js/main-115f385c414f2135e9c8.js"></script><script type="text/javascript" src=".././dist/js/a-115f385c414f2135e9c8.js"></script></head> <body> Sun Feb 18 2018 15:04:46 GMT+0800 (中国标准时间) </body> </html>
最后
以上就是英俊柠檬最近收集整理的关于webpack的最基本配置文件的全部内容,更多相关webpack内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复