1 Star 0 Fork 0

tsword/react-page-ie8

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
webpack.config.helper.js 2.64 KB
一键复制 编辑 原始数据 按行查看 历史
tsword 提交于 2018-06-28 14:42 . up config
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}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/tsword/react-page-ie8.git
git@gitee.com:tsword/react-page-ie8.git
tsword
react-page-ie8
react-page-ie8
master

搜索帮助