publicPath (dev vs. prod)

On my dev machine, I use WAMP (no Bedrock/Trellis, etc).

The path to my site on dev is:
http://some.hostname.com:1234/website.com/

In production, it would naturally be:

For the ‘publicPath’ variable in config.json, if not using Bedrock, the documentation says to put:

"publicPath": "/wp-content/themes/sage/"

So given my file paths, I would put the following (which would work for dev):

"publicPath": "/website.com/wp-content/themes/sage/"

However, on live, since the paths are different, does that mean I would have to change publicPath to:

"publicPath": "/wp-content/themes/sage/"

… every time I compile assets for production?

Or is there a way to set two publicPaths… one for dev, one for prod?

1 Like

Set it in config.js with a conditional statement or something.

Delete this line from config.json.

Add some sort of condition to this property

Like this:

const config = mergeWithConcat({
  // ...
  publicPath: isProduction ? '/wp-content/themes/sage/' : '/website.com/wp-content/themes/sage/',
  // ...
}, userConfig)

Or if you’d like to keep the option in config.json, then you can adjust the logic in some other way, obviously. This is simply an example of how you can do it.

2 Likes

With your solution the font-awesome is not displayed on dev and prod

“devUrl”: “http://juavenel.freeboxos.fr:8080/www.juavenel.fr/”,

publicPath: isProduction ? ‘/wp-content/themes/juavenel/’ : ‘/www.juavenel.fr/wp-content/themes/juavenel/’,

error: http://juavenel.freeboxos.fr:8080/www.juavenel.fr/wp-content/themes/juavenel/vendor/fontawesome-webfont_b06871f2.ttf Failed to load resource: the server responded with a status of 404 (Not Found)

1 Like