webpack+vue搭建后续,生成html,css文件剥离,清除多余文件

本文介绍了如何使用webpack+vue搭建项目,包括使用html-webpack-plugin生成HTML,通过extract-text-webpack-plugin剥离CSS文件,以及利用clean-webpack-plugin删除多余文件,确保每次编译仅保留最新版本的资源。
摘要由CSDN通过智能技术生成

1、安装html-webpack-plugin

cnpm install --save-dev html-webpack-plugin

 

将原来的index.html改成index.tmpl.html,并移除里面的script标签。

webpack.config.js引入并配置

const htmlWebpackPlugin = require('html-webpack-plugin');

plugins: [
        new htmlWebpackPlugin({
            filename: 'index.html',
            template: 'index.tmpl.html',
			minify: {
				removeAttributeQuotes: true // 移除属性的引号
			}
        })
    ]

 

执行webpack --mode development,dits目录下就生成了编译好的index.html文件。

顺便output选项在原来基础上加上hash或chunkhash,推荐chunkhash,用来清缓存

output: {
    path: __dirname + "/dist",//打包后的文件存放的地方
    filename: "bundle-[chunkhash].js",//打包后输出文件的文件名
	publicPath: 'dist/'
  },

 

 

2、安装extract-text-webpack-plugin

cnpm install extract-text-webpac
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值