const { join, resolve } = require('path');
const path = require('path')
const fs = require('fs-extra');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const scenarioNames = fs.readdirSync(join('./src/scenarios')).filter(name => !name.startsWith('.'));
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = ({ onGetWebpackConfig }) => {
onGetWebpackConfig((config) => {
config.plugin('VueLoaderPlugin').use(VueLoaderPlugin)
config.merge({
module: {
rule: [
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
});
config.resolve.plugin('tsconfigpaths').use(TsconfigPathsPlugin, [
{
configFile: './tsconfig.json',
},
]);
config.merge({
node: {
fs: 'empty',
},
});
config.merge({
resolve: {
alias: {
"@": path.resolve(__dirname, "./src")
}
},
});
scenarioNames.forEach(name => {
const hasTsx = fs.existsSync(join(`./src/scenarios/${name}/index.tsx`));
config.merge({
entry: {
[name]: hasTsx ? require.resolve(`./src/scenarios/${name}/index.tsx`) : require.resolve(`./src/scenarios/${name}/index.ts`),
},
});
config
.plugin(name)
.use(HtmlWebpackPlugin, [
{
inject: false,
minify: false,
templateParameters: {
scenario: name,
version: new Date().getTime()
},
template: require.resolve('./public/index.ejs'),
filename: `${name}.html`,
},
]);
})
config
.plugin('preview')
.use(HtmlWebpackPlugin, [
{
inject: false,
templateParameters: {
version: new Date().getTime()
},
template: require.resolve('./public/preview.html'),
filename: 'preview.html',
},
]);
config
.plugin('archive')
.use(HtmlWebpackPlugin, [
{
inject: false,
templateParameters: {
version: new Date().getTime()
},
template: require.resolve('./public/archive.html'),
filename: 'archive.html',
},
]);
config
.plugin('eaccountingArchive')
.use(HtmlWebpackPlugin, [
{
inject: false,
templateParameters: {
version: new Date().getTime()
},
template: require.resolve('./public/eaccountingArchive.html'),
filename: 'eaccountingArchive.html',
},
]);
config
.plugin('appending')
.use(HtmlWebpackPlugin, [
{
inject: false,
templateParameters: {
version: new Date().getTime()
},
template: require.resolve('./public/appending.html'),
filename: 'appending.html',
},
]);
config.plugin('CopyWebpackPlugin').tap(([args]) => {
return [
[
{
...(args[0] || {}),
},
{ from: "./node_modules/prop-types/prop-types.js", to: "./" }
]
]
})
config.plugins.delete('hot');
config.devServer.hot(false);
const proxyHost = "http://kwesit.huawei.com"; // siT环境
config.devServer.proxy({
'/*': {},
'/icp/comment': {
target: proxyHost,
// logLevel: 'debug',
changeOrigin: true,
secure: false
},
'/fin/front/one/gw': {
target: proxyHost,
changeOrigin: true,
secure: false
},
'/efinance': {
target: proxyHost,
changeOrigin: true,
secure: false
},
// '/efinance/icp/designstudio/services/jalor/lookup':{
// target: proxyHost,
// changeOrigin: true,
// secure: false
// },
});
// config.optimization.minimize(true),
config.module // fixes https://github.com/graphql/graphql-js/issues/1272
.rule('mjs$')
.test(/\.mjs$/)
.include
.add(/node_modules/)
.end()
.type('javascript/auto');
config.optimization
.splitChunks({
name: 'vendor',
chunks: 'all',
cacheGroups: {
vendor: {
test: /node_modules/,
chunks: 'initial',
name: 'vendor',
enforce: true,
},
},
});
});
};
上面的代码添加 config.optimization
.splitChunks({
name: 'vendor',
chunks: 'all',
cacheGroups: {
vendor: {
test: /node_modules/,
chunks: 'initial',
name: 'vendor',
enforce: true,
},
},
});后页面白屏了,没有错误信息,为什么?怎么解决?
最新发布