Webpack chunk files on CDN server

2019-09-18 17:16发布

问题:

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>

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?

回答1:

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

In my proj I have smth like

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

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