webpack.03-打包js同时生成html页面

新建空文件夹:cmdhtml

npm init -y
cnpm i -D webpack webpack-cli

文件夹和文件webpack

src(文件夹)web

index.html
<script src="test.js">
test.js
console.log(123)
安装插件(生成html):HtmlWebpackPlugin------> https://webpack.js.org/plugins/html-webpack-plugin/
cnpm install --save-dev html-webpack-plugin
webpack.config.js
varHtmlWebpackPlugin\=require('html-webpack-plugin');

module.exports\= {

entry: './src/main.js',

plugins: \[newHtmlWebpackPlugin()\]

};
运行打包命令:
webpack src/test.js

生成文件夹和文件npm

dist(文件夹)ui

index.html
main.js

未完待续...插件

相关文章
相关标签/搜索