|
|
let projectName = process.argv[3]
|
|
|
let glob = require('glob')
|
|
|
// const CopyWebpackPlugin = require('copy-webpack-plugin') // 这里引入`这个CopyWebpackPlugin`插件
|
|
|
// let path = require('path');
|
|
|
function getEntry() {
|
|
|
let entries = {}
|
|
|
if (process.env.NODE_ENV == 'production') {
|
|
|
entries = {
|
|
|
index: {
|
|
|
// page的入口
|
|
|
entry: 'src/views/' + projectName + '/main.js',
|
|
|
// 模板来源
|
|
|
template: 'public/index.html',
|
|
|
// 在 dist/index.html 的输出
|
|
|
filename: 'index.html',
|
|
|
// 当使用 title 选项时,
|
|
|
// template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
|
|
|
title: projectName,
|
|
|
// 在这个页面中包含的块,默认情况下会包含
|
|
|
// 提取出来的通用 chunk 和 vendor chunk。
|
|
|
chunks: ['chunk-vendors', 'chunk-common', 'index']
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
let items = glob.sync('./src/views/*/main.js')
|
|
|
for (let i in items) {
|
|
|
let filepath = items[i]
|
|
|
let fileList = filepath.split('/');
|
|
|
let fileName = fileList[fileList.length - 2];
|
|
|
// // TODO 只打包正在编码的项目
|
|
|
if (fileName != "screenAdaptation") { //superFusionPlatform screenAdaptation
|
|
|
continue;
|
|
|
}
|
|
|
entries[fileName] = {
|
|
|
entry: `src/views/${fileName}/main.js`,
|
|
|
// 在 dist/index.html 的输出
|
|
|
filename: `${fileName}.html`,
|
|
|
title: `${fileName}`,
|
|
|
// 提取出来的通用 chunk 和 vendor chunk。
|
|
|
chunks: ['chunk-vendors', 'chunk-common', fileName]
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return entries
|
|
|
}
|
|
|
|
|
|
let pages = getEntry()
|
|
|
module.exports = {
|
|
|
lintOnSave: false, //禁用eslint
|
|
|
outputDir: 'dist/' + projectName,
|
|
|
productionSourceMap: false,
|
|
|
pages: pages,
|
|
|
publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
|
|
|
devServer: {
|
|
|
overlay: {
|
|
|
// 让浏览器 overlay 同时显示警告和错误
|
|
|
warnings: true,
|
|
|
errors: true
|
|
|
},
|
|
|
contentBase: 'dist',
|
|
|
compress: false, //gzip
|
|
|
disableHostCheck: true,
|
|
|
port: "80",
|
|
|
clientLogLevel: 'error', //浏览器控制台日志,默认info
|
|
|
open: false,
|
|
|
inline: true,
|
|
|
hot: true, //开启HMR
|
|
|
publicPath: '/', //默认/,确保 publicPath 总是以斜杠(/)开头和结尾。
|
|
|
proxy: {
|
|
|
'/dsideal_yy/': {
|
|
|
target: 'http://10.10.11.190',
|
|
|
changeOrigin: true,
|
|
|
secure: false
|
|
|
},
|
|
|
'/dsSzxy/': {
|
|
|
target: 'http://10.10.11.190',
|
|
|
changeOrigin: true,
|
|
|
secure: false
|
|
|
},
|
|
|
'': {
|
|
|
target: 'http://10.10.11.190',
|
|
|
pathRewrite: { "^": "/dsideal_yy/" },
|
|
|
changeOrigin: true,
|
|
|
secure: false
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
// configureWebpack:{
|
|
|
// plugins: [
|
|
|
// new CopyWebpackPlugin([
|
|
|
// {
|
|
|
// from:path.resolve(__dirname, 'src','views',projectName,'static'),
|
|
|
// to: path.resolve(__dirname,'dist',projectName),
|
|
|
// }
|
|
|
// ])
|
|
|
// ]
|
|
|
// }
|
|
|
// chainWebpack:config=>{
|
|
|
// config.module.rule('images').test(/\.(png|jpe?g|gif|svg)(\?.*)?$/)
|
|
|
// .use('image-webpack-loader').loader('image-webpack-loader')
|
|
|
// .options({bypassOnDebug:true}).end()
|
|
|
// }
|
|
|
|
|
|
}
|