浏览器通常限制来自给定子域的最大并行负载量。因此,我希望将资产加载扩展到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)
}),
}
}发布于 2020-04-28 01:44:19
最后,这个包起了作用:https://github.com/agoldis/webpack-require-from
只需确保使用以下内容加载全局函数:
if (config.entry.client) {
config.entry.client.unshift(path.resolve(__dirname, 'globals.js'));
}https://stackoverflow.com/questions/61355843
复制相似问题