我如何配置Razzle.js以从多个CDN提供服务资产?

问题描述 投票:0回答:1

浏览器通常会限制来自给定子域的最大并行负载。因此,我想将资产负载分散到4个CDN中:

使用类似的东西(基于文件名)来确定CDN号:

"/static/media/asset-name.6d24aee6.png".split('').reduce((a, b) => a + b.charCodeAt(0), 0) % 4

我如何在Razzle中做到这一点?

到目前为止,这就是我所拥有的。在razzle.config.js

const PUBLIC_PATH = process.env.PUBLIC_PATH || '/';

module.exports = {
  modify: (config, { dev, target }, webpack) => {
    if (!dev) {
      config.devtool = false;

      // Use the CDN in production
      config.output = {
        publicPath: PUBLIC_PATH
      };
    }

    config.plugins.push(
      new webpack.DefinePlugin({
        'process.env.PUBLIC_PATH': JSON.stringify(PUBLIC_PATH)
      }),
    }
 }

webpack cdn razzle
1个回答
0
投票

最后,该程序包帮助:https://github.com/agoldis/webpack-require-from

只需确保使用以下方式加载全局函数:

if (config.entry.client) {
   config.entry.client.unshift(path.resolve(__dirname, 'globals.js'));
}
© www.soinside.com 2019 - 2024. All rights reserved.