Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom manifest filename #110

Closed
arthvrian opened this issue Jul 28, 2022 · 4 comments
Closed

Custom manifest filename #110

arthvrian opened this issue Jul 28, 2022 · 4 comments

Comments

@arthvrian
Copy link

Laravel Vite Plugin Version: 0.5.2
Laravel Version: 9.19
Node Version: 16.16.0
NPM Version: 8.11.0
Vite : 3.0.3
Host operating system: Windows 10
Web Browser & Version: Brave 1.41 (Chromium 103)
Running in Sail / Docker: No

Description

Vite allows setting a custom manifest filename https://vitejs.dev/config/build-options.html#build-manifest because the default filename may conflict if you are building a PWA or Chrome extension or whatever

This option is overridden by this plugin (maybe here? https://github.com/laravel/vite-plugin/blob/main/src/index.ts#L105) and always overrides the manifest.json file

Config

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    build: {
        manifest: 'vite-manifest.json',
        emptyOutDir: false,
        outDir: "public/",
    },
    plugins: [
        laravel({
            buildDirectory: "./",
            input: [
                'resources/css/app.css',
                'resources/js/app.js',
            ],
        }),
    ],
});

Output with laravel plugin

> build
> vite build --config vite.config.js

vite v3.0.3 building for production...
✓ 58 modules transformed.
public/manifest.json             0.23 KiB
public/assets/app.4ee680d5.css   0.02 KiB / gzip: 0.04 KiB
public/assets/app.d81e8d40.js    90.63 KiB / gzip: 33.07 KiB

Output without laravel plugin

> build
> vite build --config vite.config.js

vite v3.0.3 building for production...
✓ 58 modules transformed.
public/vite-manifest.json        0.23 KiB
public/assets/app.4ee680d5.css   0.02 KiB / gzip: 0.04 KiB
public/assets/app.f223d706.js    90.63 KiB / gzip: 33.07 KiB
@jessarcher
Copy link
Member

Hi @arthvrian,

If we were to do this, we'd also need to provide a way to specify the custom manifest location on the Laravel side of things too.

It should be fairly straight-forward, especially after laravel/framework#43442 is merged.

Thoughts @timacdonald?

@timacdonald
Copy link
Member

timacdonald commented Jul 29, 2022

@arthvrian are you actually experiencing this conflict? Is there any specific reason you are trying to put things in the root /public directory?

If you are doing this, isn't it also deleting your index.php, robots.txt, favicon.ico` and everything else that is static in the public directory (as Vite clears everything out of the build directory when it builds the assets)? I would imagine doing this renders your Laravel application un-usable as it can no longer receive requests?

@arthvrian
Copy link
Author

@jessarcher you are right

@timacdonald I'm just trying to mimic the behaviour of -mix- using -vite-, taking advantage of the speed of -vite- to compile, but leaving the resulting files in the same path that -mix- does/did, so I don't have to modify (for now, a lot of) blade templates

After a few tries, I realized that it's much easier to do it with the plain -vite- config, without involving the laravel plugin (in a new test project, I'll try the actual target project later), but it would be a good enhancement for the plugin

For your last question, that's what this -vite- option emptyOutDir is for, update your compiled assets without removing anything from external sources

@jessarcher
Copy link
Member

It sounds like you've got a workaround, so I will close this for now. I'm not keen on adding a new configuration option to this plugin and to the framework to mimic Mix. We can always revisit it if another use case requires a different manifest name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants