59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
|
let fs = require('fs')
|
|||
|
let path = require('path')
|
|||
|
let HtmlWebpackPlugin = require('html-webpack-plugin')
|
|||
|
let ExtractTextPlugin = require('extract-text-webpack-plugin')
|
|||
|
let HtmlWebpackLayoutPlugin = require('html-webpack-layout-plugin')
|
|||
|
|
|||
|
//------------------------------
|
|||
|
// 读取src/js下的页面入口目录
|
|||
|
// 除了common和lib外都是各个页面对应的目录
|
|||
|
// 构建HtmlWebpackPlugin对象以创建页面
|
|||
|
// 其中页面filename为{{目录名称}}.html
|
|||
|
// 页面模板为src/view/{{目录名称}}.html
|
|||
|
// 页面的chunks只有一个,就是[{{目录名称}}]
|
|||
|
//------------------------------
|
|||
|
|
|||
|
let files = fs.readdirSync('./src/js')
|
|||
|
|
|||
|
let plugins = []
|
|||
|
|
|||
|
|
|||
|
|
|||
|
files.forEach((file) => {
|
|||
|
|
|||
|
if (file === 'common' || file === 'utils') {
|
|||
|
return
|
|||
|
}
|
|||
|
// Add start 2018/8/24 17:13 kangzhi
|
|||
|
// 更改编译规则,只编译 指定 模块
|
|||
|
// if (file !== 'frame'
|
|||
|
// && !/run-query_yuetannanjie/.test(file)
|
|||
|
// && !/run-query/.test(file)
|
|||
|
// && !/report/.test(file)
|
|||
|
// // && !/data-board_lifengyagao/.test(file)
|
|||
|
// ) {
|
|||
|
// return
|
|||
|
// }
|
|||
|
// Add end 2018/8/24 17:13 kangzhi
|
|||
|
|
|||
|
let filename = (file + '.html')
|
|||
|
|
|||
|
let opts = {
|
|||
|
inject: 'body',
|
|||
|
filename: filename,
|
|||
|
template: ('./src/view/' + file + '.html'),
|
|||
|
chunksSortMode: 'manual',
|
|||
|
chunks: [file]
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
opts.layout = ('./src/view/common/layout.html')
|
|||
|
|
|||
|
|
|||
|
plugins.push(new HtmlWebpackPlugin(opts))
|
|||
|
|
|||
|
})
|
|||
|
|
|||
|
plugins.push(new HtmlWebpackLayoutPlugin())
|
|||
|
|
|||
|
module.exports = plugins
|