<%= htmlWebpackPlugin.options.title %>
vue.config.js
:module.exports = {
pages: {
page1: {
// 入口文件,必须
entry: 'src/pages/page1/main.js',
// 应用模板,非必须,如省略默认与模块同名(理解为此对象的KEY值->page1)
template: 'public/page1.html',
// 编译后 dist 目录中输出的HTML文件名,非必须,如省略默认与模块同名(理解为此对象的KEY值->page1)
filename: 'page1.html'
},
page2: {
entry: 'src/pages/page2/main.js',
template: 'public/page2.html',
filename: 'page2.html'
}
}
}
也可以简化为:
module.exports = {
pages: {
page1: 'src/pages/page1/main.js',
page2: 'src/pages/page2/main.js'
}
}
http://localhost:8081/page1#/
http://localhost:8081/page2#/
publicPath: process.env.VUE_APP_ENV === 'production'
? '././'
: '/',
vue2
entry: {
// app: './src/main.js'
page1: './src/pages/page1/main.js',
page2: './src/pages/page2/main.js'
},
// new HtmlWebpackPlugin({
// filename: 'index.html',
// template: 'index.html',
// inject: true
// }),
new HtmlWebpackPlugin({
filename: 'page1.html',
template: 'page1.html',
inject: true,
chunks: ['page1']
}),
new HtmlWebpackPlugin({
filename: 'page2.html',
template: 'page2.html',
inject: true,
chunks: ['page2']
}),
// new HtmlWebpackPlugin({
// filename: config.build.index,
// template: 'index.html',
// inject: true,
// minify: {
// removeComments: true,
// collapseWhitespace: true,
// removeAttributeQuotes: true
// // more options:
// // https://github.com/kangax/html-minifier#options-quick-reference
// },
// // necessary to consistently work with multiple chunks via CommonsChunkPlugin
// chunksSortMode: 'dependency'
// }),
new HtmlWebpackPlugin({
filename: config.build.page1,
template: 'page1.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
},
chunksSortMode: 'dependency',
chunks: ['manifest', 'vendor', 'page1']
}),
new HtmlWebpackPlugin({
filename: config.build.page2,
template: 'page2.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
},
chunksSortMode: 'dependency',
chunks: ['manifest', 'vendor', 'page2']
}),
// index: path.resolve(__dirname, '../dist/index.html'),
page1: path.resolve(__dirname, '../dist/page1.html'),
page2: path.resolve(__dirname, '../dist/page2.html'),
npm run dev
路径:http://localhost:8080/page1.html#/
http://localhost:8080/page2.html#/
npm run build
若引用路径不对,config 中 index.js 中修改:assetsPublicPath: './', // 路径中携带 #
assetsPublicPath: '/', // 路径中不携带 #
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
publicPath: '../../',
fallback: 'vue-style-loader'
})
} else {
return ['vue-style-loader'].concat(loaders)
}