网络包版本"webpack": "^4.32.2",
我有两个 webpack 包,每个包代表一个不同的网站。在这两个我都有不同的模块同名:
./app/shared/logo/logo.jsx
当我在客户端级别(不触发页面重新加载)从网站 A 导航到网站 B
网站 B 尝试使用来自网站 A 的 logo.jsx 并且网站中断。我得到了使用 output.jsonpFunction 的建议,但仍然有相同的结果。
站点 A 配置:
{name: 'client',
target: 'web',
mode: 'development',
devtool: 'inline-source-map',
performance: {
hints: false,
},
entry: { main: `${paths.srcClient}/mainfile.js` },
output: {
path: paths.clientBuild,
publicPath: paths.publicPath,
filename: 'js/websiteA-[name]-[contenthash:8].js',
chunkFilename: 'js/websiteA-[name]-[contenthash:8].js',
libraryTarget: 'umd',
library: 'websiteA',
crossOriginLoading: 'anonymous',
jsonpFunction: 'websiteA',
},
module: {
rules: clientLoaders,
},
resolve: { ...resolvers },
plugins: [...plugins.client],
node: {
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty',
},
externals: {
react: 'react',
'react-dom': 'react-dom',
'styled-components': 'styled-components',
axios: 'axios',
},
stats: {
cached: false,
cachedAssets: false,
chunks: false,
chunkModules: false,
colors: true,
hash: false,
modules: false,
reasons: false,
timings: true,
version: false,
},
};
网站 B
{
name: 'client',
target: 'web',
mode: 'development',
devtool: 'inline-source-map',
performance: {
hints: false,
},
entry: { main: `${paths.srcClient}/mainFile.js` },
output: {
path: paths.clientBuild,
publicPath: paths.publicPath,
filename: 'js/websiteB-[name]-[contenthash:8].js',
libraryTarget: 'umd',
jsonpFunction: 'webpackJsonp_websiteB',
umdNamedDefine: true,
},
module: {
rules: clientLoaders,
},
resolve: { ...resolvers },
plugins: [...plugins.client],
node: {
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty',
},
externals: {
react: 'react',
'react-dom': 'react-dom',
'styled-components': 'styled-components',
axios: 'axios',
},
stats: {
cached: false,
cachedAssets: false,
chunks: false,
chunkModules: false,
colors: true,
hash: false,
modules: false,
reasons: false,
timings: true,
version: false,
},
};