publicPath (dev vs. prod)

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

The path to my site on dev is:

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": "/"

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/' : '/',
  // ...
}, 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.


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

“devUrl”: “”,

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

error: Failed to load resource: the server responded with a status of 404 (Not Found)

1 Like