Home > Mobile >  Why router.base doesn't work for static src during 'npm run build' (Nuxt js)?
Why router.base doesn't work for static src during 'npm run build' (Nuxt js)?

Time:11-01

Nuxt.config.js

const ROUTER_BASE = `/${process.env.ENTITY.toLowerCase()}/`;
export default {
 router : {
 base : ROUTER_BASE
 },
}

And there is also a static SRC for the image in the component <img src="/mockups/macbookpro_01.png" />

When "npm run dev" the picture is displayed correctly, while a line about the redirect appears in the terminal: i [Development] Redirecting from /mockups/macbookpro_01.png to /my/mockups/macbookpro_01.png (router.base specified)

But when I build "npm run build", the paths do not change at the picture and, accordingly, the picture is not available in the assembly. Tell me how to set up the build correctly?

CodePudding user response:

Have you made sure that the environment variable ENTITY is set in the environment you run the build in?

To make sure it's not a problem with the env var you could try temporarily changing it to

const ROUTER_BASE = "/my/";

If it works with that base hard coded then it must be a problem with the enviroment variable you're using.

  • Related