vue公用html,vue+webpack配置+多页面入口+提取公共js

const path=require(‘path‘)

const VueLoaderPlugin=require(‘vue-loader/lib/plugin‘)

const HtmlWebpackPlugin=require(‘Html-Webpack-Plugin‘)

const {cleanwebpackPlugin}=require(‘clean-webpack-plugin‘)

module.exports={

entry:{

aa:‘./src/index.js‘,//....多页面入口

},

mode:‘development‘,

output:{

filename:‘[name].[chunkhash].js‘,

path:__dirname+‘/dist‘,

chunkFilename:‘[name].chunk.js‘},

module:{

rules:[

{

test:/\.js$/,

exclude:/node_modules/,

loader:‘babel-loader‘,

},

{

test:/\.vue$/,

loader:‘vue-loader‘},

{

test:/\.css$/,

loader:‘style-loader!css-loader‘},

{

test:/\.(eot|svg|ttf|woff|woff2)$/,

loader:‘file-loader‘}

]

},

resolve:{

alias:{

vue:‘vue/dist/vue.min.js‘,‘@‘:path.resolve(‘src‘)

}

},

optimization: {

splitChunks: {

cacheGroups: {//注意: priority属性

//其次: 打包业务中公共代码

commons: {

name:"commons",

chunks:"all",

minSize:1,

priority:0},//首先: 打包node_modules中的文件

vendor: {

name:"vendor",

test:/[\\/]node_modules[\\/]/,

chunks:"all",

priority:10}

}

}

},

plugins:[newVueLoaderPlugin(),newHtmlWebpackPlugin({

chunks:[‘aa‘,‘commons‘,‘vendor‘],

template:‘template.html‘,

filename:‘aa.html‘,

hash:true,//为了更好的 cache,可以在文件名后加个 hash

minify: {

collapseWhitespace:true, //把生成的 index.html 文件的内容的没用空格去掉,减少空间

},

}),newHtmlWebpackPlugin({

chunks:[‘bb‘,‘commons‘,‘vendor‘],

template:‘template.html‘,

filename:‘bb.html‘,

hash:true,//为了更好的 cache,可以在文件名后加个 hash

minify: {

collapseWhitespace:true, //把生成的 index.html 文件的内容的没用空格去掉,减少空间

},

}),newCleanWebpackPlugin()

]

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值