What path to use, to read a file from public folder?

The "dev" public folder is in another location than the "build" public folder. Using filesystem tools, how can you access these files in a way that works both in "dev" and in "prod"? I currently use this:
const isBuild = import.meta.url.includes('.output');
const staticPath = isBuild ? '../public' : '../../static';

legalFilePath = decodeURI(
new URL(
staticPath + '/legaltexts/' + v.AppointmentPosition.Appointment.legal_filename,
import.meta.url
).pathname
);

const fileFound = existsSync(legalFilePath);
const isBuild = import.meta.url.includes('.output');
const staticPath = isBuild ? '../public' : '../../static';

legalFilePath = decodeURI(
new URL(
staticPath + '/legaltexts/' + v.AppointmentPosition.Appointment.legal_filename,
import.meta.url
).pathname
);

const fileFound = existsSync(legalFilePath);
In nuxt.config.js we use the legacy "static" folder instead of "public" for historical reasons:
dir: {
public: 'static'
},
dir: {
public: 'static'
},
This does work, but it feels like a hack. Is there a clean way to generate a file path to the public folder that works both in "dev" and in "build"?
0 Replies
No replies yetBe the first to reply to this messageJoin