statamic / ssg

The official Statamic Static Site Generator
229 stars 23 forks source link

Vite public/build folder does not get automatically added to the storage/app/static folder. #122

Closed the-programmer-alex closed 1 year ago

the-programmer-alex commented 1 year ago

By default, vite compiles css/js into /public/build.

Insert CSS/JS in Head
<head>
    @vite(['resources/css/site.css', 'resources/js/site.js'])
 </head>

Build Vite for prod

  yarn run vite build

  < output >

public/build/manifest.json    
public/build/assets/site.ef255fe8.js    
public/build/assets/site.5acdf84b.css 

When running php please ssg:generate the storage/app/static contains doesn't contain vite's build folder. Which then means the css/js won't link.

index.html

<head> ...
    <link rel="preload" as="style" href="https://domain.com/build/assets/site.5acdf84b.css" />
    <link rel="modulepreload" href="https://domain.com/build/assets/site.ef255fe8.js" />
    <link rel="stylesheet" href="https://domain.com/build/assets/site.5acdf84b.css" />
    <script type="module" src="https://domain.com/build/assets/site.ef255fe8.js"></script>
</head>

Notice how it's trying to find the /build/assets folder? The very one that doesn't exist. Now the solution is to copy the /build folder afterwards, but that will mess people who don't know up. Especially since vite is default for Laravel 9+

Versions

Laravel: ^9
Satamic/ssg: 1.2.0
the-programmer-alex commented 1 year ago

My package.json script

        "build": "vite build",
        "deploy": "yarn run build && php please ssg:generate && yarn run copy-build ",
        "copy-build": "cp -r public/build/ storage/app/static/"
duncanmcclean commented 1 year ago

You need to specify that you want the public/build directory to be copied over, otherwise it won't do it.

https://github.com/statamic/ssg/blob/master/config/ssg.php#L41