Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

Webpack output.jsonpFunction fails to prevent naming colision

webpack version "webpack": "^4.32.2",

I have two webpack bundles, each one represent a different website. in both I have different modules with same name:

./app/shared/logo/logo.jsx

When I navigate at client level (without trigger a page reload) from website A to website B

website B try to use logo.jsx from site A and the site breaks. I got a suggestion of use output.jsonpFunction but still having same result.

Site A config:

 {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,
  },
};

website 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,
  },
};
question from:https://stackoverflow.com/questions/65909752/webpack-output-jsonpfunction-fails-to-prevent-naming-colision

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...