Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maharzan's avatar

npm run build assets linking to root folder instead of sub folder

I am creating this project under a sub folder in one of my domains. I have the nginx configured so the sub folder thing is loading ok. But I realized that most of the js assets from npm run build, are actually loading from the root folder instead of sub folder which is not what I am looking for. Upon further investigation, I saw the asset files are loading like this in html...

<link rel="modulepreload" as="script" crossorigin="" href="/build/assets/Login-XYc9sZ4C.js">

and I see a lot of files loading this way thus nothing on the site is working although its rendering. I tried to search over and tested few things but its not working. Strangely, some of the URLs like this is loading full url so they are loading correctly.

My question is how or what do I set so that the href loads the full url or maybe remove that / in front of the /build href?

I do have these in the .env file

APP_ENV=production
APP_KEY=base64:key
APP_DEBUG=false
APP_URL=https://myurl.com/timesheet

SESSION_PATH=/timesheet
SESSION_DOMAIN=myurl.com

Thanks.

1 like
12 replies
maharzan's avatar

In local and upload the files into the server

1 like
vincent15000's avatar

Have you configured an output folder for the manifest ?

maharzan's avatar

I have not.. I haven't done a subfolder yet so don't know what needs to be done. All other "parent" directory apps have been working fine this way. How/What do we need to configure in manifest?

My manifest.json looks something like this..

 "_InputError.vue_vue_type_script_setup_true_lang-BzZ7bi1s.js": {
"file": "assets/InputError.vue_vue_type_script_setup_true_lang-BzZ7bi1s.js",
"name": "InputError.vue_vue_type_script_setup_true_lang",
"imports": [
  "resources/js/app.ts"
]
},
maharzan's avatar

I just saw in app.php a class named AddLinkHeadersForPreLoadedAssets.php

public function handle($request, $next)
{
    return tap($next($request), function ($response) {
        if ($response instanceof Response && Vite::preloadedAssets() !== []) {
            $response->header('Link', (new Collection(Vite::preloadedAssets()))
                ->map(fn ($attributes, $url) => "<{$url}>; ".implode('; ', $attributes))
                ->join(', '), false);
        }
    });
}

Is there something here?

1 like
maharzan's avatar

I am using laravel 12 with vue inertia starter kit. vendor/laravel/framework/src/Illuminate/Http/Middleware/AddLinkHeadersForPreloadedAssets.php

1 like
maharzan's avatar
import vue from '@vitejs/plugin-vue';
import autoprefixer from 'autoprefixer';
import laravel from 'laravel-vite-plugin';
import path from 'path';
import tailwindcss from 'tailwindcss';
import { resolve } from 'node:path';
import { defineConfig } from 'vite';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/js/app.ts'],
            ssr: 'resources/js/ssr.ts',
            refresh: true,
        }),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
    ],
    resolve: {
        alias: {
            '@': path.resolve(__dirname, '/resources/js'),
            'ziggy-js': resolve(__dirname, 'vendor/tightenco/ziggy'),
        },
    },
    css: {
        postcss: {
            plugins: [tailwindcss, autoprefixer],
        },
    },
});
1 like
vincent15000's avatar

@maharzan Not sure, but you have perhaps something to do with these 2 lines.

base: null,
includeAbsolute: false,
maharzan's avatar

In package.json there is this

"build": "vite build",

I changed to

"build": "vite build --base /timesheet",

and the assets seems to be resolved but I could only load the login page. I couldn't make the other routes work. So, I have now opted to use the subdomain instead which seem to work without much thinking..

Thanks for your help everyone.

1 like
vincent15000's avatar

@maharzan Hmmm ... I wonder if you don't have a misconfiguration on your webhosting (nginx perhaps).

Please or to participate in this conversation.