Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make webpack use multiple urls for publicPath config

Tags:

webpack

cdn

I know in webpack you can set the publicPath to a cdn URL like so:

// Example CDN
output: {
    path: "/home/proj/cdn/assets/[hash]",
    publicPath: "http://cdn.example.com/assets/[hash]/"
}

but how do you accomplish the trick of having multiple CDN aliases to improve load performance?

eg:

  • http://cdn1.example.com
  • http://cdn2.example.com
  • http://cdn3.example.com
  • http://cdn4.example.com
like image 650
Christian Schlensker Avatar asked Nov 10 '22 09:11

Christian Schlensker


1 Answers

I don't think webpack supports that yet. I had a quick look at the source and it seems to expect a static value. You probably should open an issue unless you can find a matching one.

As a temporary hack you could try something a little clever. Set publicPath to something that's easy to replace. Then, using another script, detect those and perform replacement according to your logic. That might be a good workaround for now.

like image 165
Juho Vepsäläinen Avatar answered Dec 05 '22 12:12

Juho Vepsäläinen