CDN服务器上的Webpack块文件 [英] Webpack chunk files on CDN server

查看:276
本文介绍了CDN服务器上的Webpack块文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个angular 2应用,并且我正在使用WebPack进行捆绑.WebPack生成块文件,这些块文件在加载时会动态添加到网页中:

I have an angular 2 app and I am using WebPack for bundling. WebPack generates chunk files which are dynamically added to the webpage when it is loaded:

<script type="text/javascript" charset="utf-8" async="" src="0.b422af7997bfeca78d4.chunk.js"></script>

我希望这些块文件位于CDN服务器上.如何在脚本标记的src路径中添加CDN路径?

I want these chunk files to be located on a CDN server. How can I add the CDN path in the src path of the script tag?

推荐答案

如果我的问题正确,则可以使用 publicPath

If I've got your question correct you can use publicPath Docs

在我的项目中,我像

output: {
  path: helpers.root('dist'),
  publicPath: 'https://mycdn.com/',
  // other config goes here
}

但这仅适用于webpack产品构建,因此它不会为开发环境和本地环境放置任何CDN.

But this goes only for webpack prod build, so it doesn't put any cdn for the dev env and local ones.

这篇关于CDN服务器上的Webpack块文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆