代码拉取完成,页面将自动刷新
const path = require('path');
const fs = require('fs');
const glob =require('glob');
const HtmlWebpackPlugin = require('html-webpack-plugin');
function getView(globPath,flag){
let files = glob.sync(globPath);
let entries = {},
entry, dirname, basename, pathname, extname;
files.forEach(item => {
entry = item;
dirname = path.dirname(entry);//当前目录
extname = path.extname(entry);//后缀
basename = path.basename(entry, extname);//文件名
pathname = path.join(dirname, basename);//文件路径
if (extname === '.html' || extname === '.ejs') {
entries[pathname] = './' + entry;
}
else if (extname === '.js') {
entries[basename] = entry;
}
//else if(extname === '.ejs'){
// filename: 'index.html',
// template: path.resolve(__dirname, 'src/index.ejs'),
// chunks: ['manifest', 'vendor', 'index'],
// }
//}
});
return entries;
}
function extendEntires(config){
let entriesObj = getView('./src/*.js');
Object.assign(entriesObj,{
vendor: ['es5-shim', 'es5-shim/es5-sham', 'es6-promise', 'fetch-ie8', 'console-polyfill']
});
config.entry=entriesObj;
return config;
}
function extendHtmlPluginList(config){
let pages = Object.keys(getView('./src/*.ejs'));
pages.forEach(pathname => {
let htmlname = pathname.split('src\\')[1]||pathname.split('src\/')[1];
// let conf = {
// filename: `${htmlname}.html`,
// template: `${pathname}.ejs`,
// hash: true,
// chunks:[htmlname],
// minify: {
// removeAttributeQuotes:true,
// removeComments: true,
// collapseWhitespace: true,
// removeScriptTypeAttributes:true,
// removeStyleLinkTypeAttributes:true
// }
// };
let conf= {
filename: `${htmlname||pathname}.html`,
template: path.resolve(__dirname,`${pathname}.ejs`),
chunks: ['manifest', 'vendor', htmlname],
};
config.plugins.push(new HtmlWebpackPlugin(conf));
});
let pluginsLen=config.plugins.length;
// console.log(' \n\n--------------')
// console.log(pages.length,JSON.stringify(config.plugins[pluginsLen-1]))
// console.log(' \n\n--------------')
return config;
}
function extendConfig(config){
extendEntires(config);
extendHtmlPluginList(config);
return config;
}
module.exports={extendEntires,extendHtmlPluginList,extendConfig}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。