alias in the file path #49
-
|
Hi! It throws an error, when trying to set an alias in the file path. Although the file exists. <?php require $_SERVER['DOCUMENT_ROOT'] . '%BASE%/system/main.php';
|
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 7 replies
-
|
Hi, thanks for using my plugin! Just so you know: during development the Can you share where you project is located?
By the looks of it |
Beta Was this translation helpful? Give feedback.
-
|
The path is correct. I've tried various options. Original error vite.config.js export default defineConfig(({ command, mode }) => {
const publicBasePath = mode === 'production' ? '/wp-content/themes/recstom/dist/' : '/';
const base = command === 'serve' ? '/' : publicBasePath;
const BASE = base.substring(0, base.length - 1);
return {
base,
publicDir: command === 'build' ? 'raw' : 'public',
css: { preprocessorOptions: { scss: { api: 'modern-compiler' } } },
server: { port: 3000 },
build: { assetsDir: 'public', emptyOutDir: true },
define: {
'import.meta.env.BASE': JSON.stringify(BASE),
},
resolve: {
alias: { '~/': fileURLToPath(new URL('./src/', import.meta.url)) },
},
plugins: [
imagetools(),
usePHP({
entry: [
'index.php',
'configs/env.php',
'pages/**/*.php',
'partials/**/*.php',
],
rewriteUrl(requestUrl) {
const filePath = fileURLToPath(new URL('.' + requestUrl.pathname, import.meta.url));
const publicFilePath = fileURLToPath(new URL( './public' + requestUrl.pathname, import.meta.url));
if (!requestUrl.pathname.includes('.php') && (existsSync(filePath) || existsSync(publicFilePath))) {
return undefined;
}
requestUrl.pathname = 'index.php';
return requestUrl;
},
}),
ViteEjsPlugin({ BASE }),
viteStaticCopy({
targets: [
{ src: 'public', dest: '' },
{ src: 'system', dest: '' },
{ src: 'configs', dest: '', overwrite: false },
{ src: 'vendor', dest: '' },
],
silent: command === 'serve',
}),
],
};
}); |
Beta Was this translation helpful? Give feedback.
-
|
The include paths seem to be correct:
In theory (on our systems) it's even working if you just do <?php require 'system/main.php';Does it work if you require it manually? <?php require '/Users/kan0ne/Documents/Project/kppc/system/main.php'; |
Beta Was this translation helpful? Give feedback.
-
Work fine. const publicBasePath = mode === 'production' ? '/wp-content/themes/recstom/dist/' : '/';How can I implement this? |
Beta Was this translation helpful? Give feedback.
-
|
I think I understand, what you want to do. export default defineConfig(({ command, mode }) => {
const publicBasePath = '/wp-content/themes/recstom/dist/';
const base = command === 'serve' ? '/' : publicBasePath;
const BASE = base.substring(0, base.length - 1);
return {
base,
publicDir: command === 'build' ? 'raw' : 'public',
css: { preprocessorOptions: { scss: { api: 'modern-compiler' } } },
server: { port: 3000 },
build: { assetsDir: 'public', emptyOutDir: true },
define: {
'import.meta.env.ROOT': JSON.stringify(mode === 'production' ? publicBasePath : ''),
'import.meta.env.BASE': JSON.stringify(BASE),
},
resolve: {
alias: { '~/': fileURLToPath(new URL('./src/', import.meta.url)) },
},
plugins: [
imagetools(),
usePHP({
entry: [
'index.php',
'configs/env.php',
'pages/**/*.php',
'partials/**/*.php',
],
rewriteUrl(requestUrl) {
const filePath = fileURLToPath(new URL('.' + requestUrl.pathname, import.meta.url));
const publicFilePath = fileURLToPath(new URL( './public' + requestUrl.pathname, import.meta.url));
if (!requestUrl.pathname.includes('.php') && (existsSync(filePath) || existsSync(publicFilePath))) {
return undefined;
}
requestUrl.pathname = 'index.php';
return requestUrl;
},
}),
ViteEjsPlugin({ BASE }),
viteStaticCopy({
targets: [
{ src: 'public', dest: '' },
{ src: 'system', dest: '' },
{ src: 'configs', dest: '', overwrite: false },
{ src: 'vendor', dest: '' },
],
silent: command === 'serve',
}),
],
};
});In your PHP-files you could then just: <?php require '%ROOT%system/main.php';During development it would result in |
Beta Was this translation helpful? Give feedback.
-
Yeap
didn't work
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
No problems |
Beta Was this translation helpful? Give feedback.
-
|
@kan0neego so I think I found the bug... See #50. As for now you can create a workaround:
This should work for you scenario as for now... After the bug fix the env constants will be available in all processed files. |
Beta Was this translation helpful? Give feedback.



The 2.0.0 release just came out. Try it please and tell me if you still can not conditional paths!