arnoson / kirby-vite

Use Kirby CMS together with Vite
MIT License
81 stars 7 forks source link

Is there a way to replace "dist" by nothing ? #18

Closed denisbertrandbe closed 12 months ago

denisbertrandbe commented 1 year ago

I want to have my dist files right in public/assets (and not public/dist/assets). My src files are in "src/assets". For having this to work I need to specify my arnoson.kirby-vite.outDir to '.'

Maybe I suggest to change assetProd function in kirby-vite/lib/Vite.php:97 by this :

protected function assetProd(string $file) {
      $path = option('arnoson.kirby-vite.outDir', 'dist');
      $path = $path !== '' ? $path . '/' : $path;
    return '/' . $path . $file;
  }

What do you think ?

arnoson commented 1 year ago

Sounds good! Do you want to create a PR? Otherwise I could look into it later this week

denisbertrandbe commented 1 year ago

I will create a push request soon ;-)

Thank you !

Denis On 20 Feb 2023, 13:17 +0100, Arno Schlipf @.***>, wrote:

Sounds good! Do you want to create a PR? Otherwise I could look into it later this week — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

fvsch commented 12 months ago

This is doable with Vite and this plugin as-is, I believe. You can just set the build.assetsDir to an empty string, like this:

// vite.config.js
export default {
    build: {
        // The outDir is where Vite will write build outputs, including assets
        // and the `manifest.json` (Vite 3-4) or `.vite/manifest.json` (Vite 5).
        outDir: 'public/assets',

        // Optionally: clean out the outDir before writing new files
        // emptyOutDir: true,

        // Don't create an extra 'assets' directory in the outDir for generated JS/CSS/fonts/media
        assetsDir: '',
    },
};

You could also set build.outDir to 'public' and set build.assetsDir to 'assets' (or not set it, since that's the default value), and get the same result. The difference here is that with 'public' as your build.outDir you might end up with a few issues:

So it's better to have build.outDir point to a gitignored directory that is managed only by Vite and not used by other tools. And if you want Vite assets URLs to end up looking like /assets/something-{hash}.js and not /dist/assets/something-{hash}.js, then the config I've shown above is the way to go.

arnoson commented 12 months ago

Thank you @fvsch for the information! Since I didn't receive a PR and you provided a good solution I will close this issue :)