Commit fd2317b0 authored by 邓晓峰's avatar 邓晓峰

fix: 修复无限嵌套路由渲染

parent 8917bfef
Pipeline #35010 passed with stages
in 58 minutes 12 seconds
This diff was suppressed by a .gitattributes entry.
...@@ -90,6 +90,16 @@ module.exports = { ...@@ -90,6 +90,16 @@ module.exports = {
'/CityTemp': '/CityTemp', '/CityTemp': '/CityTemp',
}, },
}, },
'/civweb4': {
target: proxyURL,
changeOrigin: true,
headers: {
'Access-Control-Allow-Origin': '*',
},
pathRewrite: {
'/civweb4': '/civweb4',
},
},
'/web4': { '/web4': {
target: proxyURL, target: proxyURL,
changeOrigin: true, changeOrigin: true,
...@@ -97,7 +107,7 @@ module.exports = { ...@@ -97,7 +107,7 @@ module.exports = {
'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Origin': '*',
}, },
pathRewrite: { pathRewrite: {
'/web4': '/web4', 'web4': 'web4',
}, },
} }
}, },
......
...@@ -65,7 +65,7 @@ const defaultConfig = { ...@@ -65,7 +65,7 @@ const defaultConfig = {
edge: 13, edge: 13,
ios: 10, ios: 10,
ie: 11, ie: 11,
}, }
}; };
module.exports = options => { module.exports = options => {
const chainConfig = new Config(); const chainConfig = new Config();
...@@ -76,7 +76,7 @@ module.exports = options => { ...@@ -76,7 +76,7 @@ module.exports = options => {
const isProd = process.env.NODE_ENV === 'production'; const isProd = process.env.NODE_ENV === 'production';
const disableCompress = process.env.COMPRESS === 'none'; const disableCompress = process.env.COMPRESS === 'none';
const isWebpack5 = webpack.version.startsWith('5'); const isWebpack5 = webpack.version.startsWith('5');
const cwd = process.cwd();
const devtool = options.devtool || false; const devtool = options.devtool || false;
chainConfig.devtool( chainConfig.devtool(
...@@ -86,9 +86,9 @@ module.exports = options => { ...@@ -86,9 +86,9 @@ module.exports = options => {
: devtool || 'cheap-module-source-map' : devtool || 'cheap-module-source-map'
: devtool, : devtool,
); );
const mfsu = defineConfig.mfsu;
const useHash = defineConfig.hash && isProd; const useHash = defineConfig.hash && isProd;
const absOutputPath = process.env.npm_config_releasepath const absOutputPath = process.env.npm_config_releasepath
? path.resolve( ? path.resolve(
process.env.npm_config_releasepath, process.env.npm_config_releasepath,
...@@ -100,7 +100,7 @@ module.exports = options => { ...@@ -100,7 +100,7 @@ module.exports = options => {
.path(absOutputPath) .path(absOutputPath)
.filename(useHash ? `[name].[contenthash:8].js` : `[name].js`) .filename(useHash ? `[name].[contenthash:8].js` : `[name].js`)
.chunkFilename( .chunkFilename(
useHash ? `[name].[contenthash:8].async.js` : `[name].chunk.js`, useHash ? `[name].[contenthash:8].async.js` : `[name].js`,
) )
.publicPath(`/${pkg.name.toLocaleLowerCase()}/`) .publicPath(`/${pkg.name.toLocaleLowerCase()}/`)
.futureEmitAssets(true) .futureEmitAssets(true)
...@@ -173,6 +173,7 @@ module.exports = options => { ...@@ -173,6 +173,7 @@ module.exports = options => {
{ libraryName: 'antd-mobile', libraryDirectory: 'es', style: true }, { libraryName: 'antd-mobile', libraryDirectory: 'es', style: true },
]), ]),
}); });
let babelOpts = { let babelOpts = {
sourceType: 'unambiguous', sourceType: 'unambiguous',
babelrc: false, babelrc: false,
...@@ -187,10 +188,17 @@ module.exports = options => { ...@@ -187,10 +188,17 @@ module.exports = options => {
chainConfig.module chainConfig.module
.rule('js') .rule('js')
.test(/\.(js|mjs|jsx|ts|tsx)$/) .test(/\.(js|mjs|jsx|ts|tsx)$/)
.exclude.add(/node_modules/) .include
.add([
cwd,
...(process.env.APP_ROOT ? [process.cwd()] : [])
]).end()
.exclude
.add(/node_modules/)
.add(/\.mfsu/)
.end() .end()
.use('babel-loader') .use('babel-loader')
.loader(require.resolve('babel-loader')) .loader(require.resolve('@umijs/deps/compiled/babel-loader'))
.options(babelOpts); .options(babelOpts);
if (defineConfig.extraBabelIncludes) { if (defineConfig.extraBabelIncludes) {
...@@ -214,6 +222,8 @@ module.exports = options => { ...@@ -214,6 +222,8 @@ module.exports = options => {
}); });
} }
const staticDir = mfsu ? 'mf-static' : 'static';
chainConfig.module chainConfig.module
.rule('images') .rule('images')
.test(/\.(png|jpe?g|gif|webp|ico)(\?.*)?$/) .test(/\.(png|jpe?g|gif|webp|ico)(\?.*)?$/)
...@@ -221,17 +231,28 @@ module.exports = options => { ...@@ -221,17 +231,28 @@ module.exports = options => {
.loader(require.resolve('url-loader')) .loader(require.resolve('url-loader'))
.options({ .options({
limit: defineConfig.inlineLimit || 10000, limit: defineConfig.inlineLimit || 10000,
name: 'static/[name].[hash:8].[ext]', name: `${staticDir}/[name].[hash:8].[ext]`,
// require 图片的时候不用加 .default // require 图片的时候不用加 .default
esModule: false, esModule: false,
fallback: { fallback: {
loader: require.resolve('file-loader'), loader: require.resolve('file-loader'),
options: { options: {
name: 'static/[name].[hash:8].[ext]', name: `${staticDir}/[name].[hash:8].[ext]`,
esModule: false, esModule: false,
}, },
}, },
}); });
chainConfig.module
.rule('avif')
.test(/\.(avif)(\?.*)?$/)
.use('file-loader')
.loader(require.resolve('file-loader'))
.options({
name: `${staticDir}/[name].[hash:8].[ext]`,
esModule: false,
});
chainConfig.module chainConfig.module
.rule('svg') .rule('svg')
...@@ -239,7 +260,7 @@ module.exports = options => { ...@@ -239,7 +260,7 @@ module.exports = options => {
.use('file-loader') .use('file-loader')
.loader(require.resolve('@umijs/deps/compiled/file-loader')) .loader(require.resolve('@umijs/deps/compiled/file-loader'))
.options({ .options({
name: 'static/[name].[hash:8].[ext]', name: `${staticDir}/[name].[hash:8].[ext]`,
esModule: false, esModule: false,
}) })
.end(); .end();
...@@ -250,7 +271,7 @@ module.exports = options => { ...@@ -250,7 +271,7 @@ module.exports = options => {
.use('file-loader') .use('file-loader')
.loader(require.resolve('file-loader')) .loader(require.resolve('file-loader'))
.options({ .options({
name: 'static/[name].[hash:8].[ext]', name: `${staticDir}/[name].[hash:8].[ext]`,
esModule: false, esModule: false,
}); });
...@@ -270,6 +291,15 @@ module.exports = options => { ...@@ -270,6 +291,15 @@ module.exports = options => {
.use('raw-loader') .use('raw-loader')
.loader(require.resolve('raw-loader')); .loader(require.resolve('raw-loader'));
if(defineConfig.workerLoader) {
chainConfig.module
.rule('worker')
.test(/.*worker.(ts|js)/)
.use('worker-loader')
.loader(require.resolve('worker-loader'))
.options(defineConfig.workerLoader);
}
css({ css({
type: 'csr', type: 'csr',
config: defineConfig, config: defineConfig,
...@@ -369,7 +399,7 @@ module.exports = options => { ...@@ -369,7 +399,7 @@ module.exports = options => {
.plugin('replaceTheme') .plugin('replaceTheme')
.use(ThemeColorReplacer, [themePluginOption]); .use(ThemeColorReplacer, [themePluginOption]);
const cwd = process.cwd();
const copyPatterns = [ const copyPatterns = [
fs.existsSync(path.join(process.cwd(), 'public')) && { fs.existsSync(path.join(process.cwd(), 'public')) && {
from: path.join(cwd, 'public'), from: path.join(cwd, 'public'),
...@@ -514,7 +544,14 @@ module.exports = options => { ...@@ -514,7 +544,14 @@ module.exports = options => {
} }
if (process.env.PROGRESS !== 'none') { if (process.env.PROGRESS !== 'none') {
chainConfig.plugin('progress').use(require.resolve('webpackbar')); chainConfig.plugin('progress').use(require.resolve('webpackbar'), [
mfsu ? {
name: 'MFSU',
color: '#facc00'
}: defineConfig.ssr ? {
name: type === 'ssr' ? 'Server': 'Client'
}: {}
]);
} }
if (process.env.FRIENDLY_ERROR !== 'none') { if (process.env.FRIENDLY_ERROR !== 'none') {
...@@ -578,20 +615,6 @@ module.exports = options => { ...@@ -578,20 +615,6 @@ module.exports = options => {
}, },
]); ]);
} }
if(defineConfig.esbuild) {
const { target = 'es2015' } = defineConfig.esbuild || {};
const optsMap = {
['csr']: {
minify: true,
target
}
};
const opt = optsMap['csr'];
chainConfig.optimization.minimize = true;
chainConfig.optimization.minimizer = [new ESBuildMinifyPlugin(opt)];
chainConfig.plugin('es-build').use(new ESBuildPlugin())
}
}, },
); );
...@@ -607,9 +630,24 @@ module.exports = options => { ...@@ -607,9 +630,24 @@ module.exports = options => {
}); });
} }
if(defineConfig.esbuild) {
const { target = 'es2015' } = defineConfig.esbuild || {};
const optsMap = {
['csr']: {
minify: true,
target
}
};
const opt = optsMap['csr'];
chainConfig.optimization.minimize = true;
chainConfig.optimization.minimizer = [new ESBuildMinifyPlugin(opt)];
chainConfig.plugin('es-build').use(new ESBuildPlugin())
}
if (defineConfig.chainWebpack) { if (defineConfig.chainWebpack) {
defineConfig.chainWebpack(chainConfig, { defineConfig.chainWebpack(chainConfig, {
type: 'csr', type: 'csr',
// mfsu,
env: process.env, env: process.env,
webpack, webpack,
createCSSRule: createCSSRuleFn, createCSSRule: createCSSRuleFn,
...@@ -647,6 +685,34 @@ module.exports = options => { ...@@ -647,6 +685,34 @@ module.exports = options => {
entry.push(require.resolve('./runtimePublicPathEntry')); entry.push(require.resolve('./runtimePublicPathEntry'));
} }
// const nodeLibs = require('node-libs-browser');
// const ProvidePlugin = webpack.ProvidePlugin;
// if(isWebpack5) {
// // ret.plugins.push({
// // new ProvidePlugin({
// // process: nodeLibs['process']
// // })
// // });
// // ret.plugins.push({
// // new ProvidePlugin({
// // Buffer: ['buffer', 'Buffer'],
// // })
// // });
// ret.resolve.fallback = {
// ...ret.resolve.fallback,
// ...Object.keys(nodeLibs).reduce((memo, key) => {
// if(nodeLibs[key]) {
// memo[key] = nodeLibs[key]
// } else {
// memo[key] = false
// };
// return memo
// }, {}),
// http: false,
// https: false,
// }
// }
ret = { ret = {
...ret, ...ret,
// mode: options.mode, // mode: options.mode,
......
...@@ -14,8 +14,38 @@ module.exports = require('./webpack.base.babel')({ ...@@ -14,8 +14,38 @@ module.exports = require('./webpack.base.babel')({
path.join(process.cwd(), 'src/app.js'), // Start with js/app.js path.join(process.cwd(), 'src/app.js'), // Start with js/app.js
], ],
optimization: { optimization: {
namedModules: true,
namedChunks: true,
runtimeChunk: {
name: "runtime",
},
splitChunks: { splitChunks: {
chunks: 'all', name: false,
chunks: "all", // all(全部), async(异步的模块),initial(同步的模块)
minSize: 20000, // 表示文件大于1k的时候才对它进行打包
minChunks: 2, // 当某个模块满足minChunks引用次数时,才会被打包。
maxAsyncRequests: 5, // 在打包某个模块的时候,最多分成5个chunk,多余的会合到最后一个chunk中
maxInitialRequests: Infinity,
automaticNameDelimiter: "~", // 当vendors或者default中的filename不填时,打包出来的文件名就会带~
cacheGroups: {
default: false,
vendors: {
// 将从node_modules中引入的模块统一打包到common.js文件中
name: "common",
chunks: "all",
minChunks: 2,
test: /[\\/]node_modules[\\/]/,
},
styles: {
// css统一打包到common.css文件中
name: "common",
chunks: "all",
minChunks: 2,
test: /\.(css|less|scss|stylus)$/,
enforce: true,
priority: 50,
},
},
}, },
}, },
plugins: [ plugins: [
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment