kit icon indicating copy to clipboard operation
kit copied to clipboard

Configure output directory (currently fixed to ".svelte-kit")

Open ecstrema opened this issue 3 years ago • 15 comments

Describe the problem

In monorepos, builds are often centralized into a single top-level build directory.

Is there anything that prevents that change from being innocent and simple?

Describe the proposed solution

In order for svelte-kit to support that, the SVELTE_KIT constant in constants.js should be replaced by a configuration option.

setting the kit.vite.build.outDir options prints an error:

build_server: The value for kit.vite.build.outDir specified in svelte.config.js has been ignored. This option is controlled by SvelteKit.

should the vite option be used, or should there be svelte-kit specific option?

Importance

nice to have

ecstrema avatar Feb 22 '22 15:02 ecstrema

I couldn't find any existing bug report/feature request for this, which surprises me. I hope I am not duplicating things here. Feel free to close if there's already a similar issue.

ecstrema avatar Feb 22 '22 15:02 ecstrema

The directory is used for more than Vite builds, so we can't use vite.build.outDir — Kit needs to control it. Having it be configurable seems reasonable, we would just need to bikeshed a name. buildDir? outDir? tmpDir? something else?

Rich-Harris avatar Feb 22 '22 17:02 Rich-Harris

The directory is used for more than Vite builds, so we can't use vite.build.outDir — Kit needs to control it.

Can't we use vite.build.outDir for more than vite builds?

ecstrema avatar Feb 22 '22 17:02 ecstrema

we would just need to bikeshed a name. buildDir? outDir? tmpDir? something else?

I have a preference for outDir, just because it's clearer than tmpDir, is more than just a buildDir, and is in line with vite.

ecstrema avatar Feb 22 '22 17:02 ecstrema

Figuring the same issue for adding sveltekit to https://github.com/jhipster, as a monorepo project generator, while we can't change the output dir, we can't merge the sveltekit pr

flcarre avatar Mar 01 '22 06:03 flcarre

It would be a great help to create a better Nx integration

DominikPieper avatar Mar 01 '22 07:03 DominikPieper

Finaly found a workarround using adapter-static

kit: { adapter: adapter({ pages: 'target/classes/static/', assets: 'target/classes/static/', fallback: 'index.html', }), appDir: '_app',

flcarre avatar Mar 01 '22 07:03 flcarre

@Rich-Harris You wanted to keep this open until the case of outDir being outside the CWD was sorted out, right?

Conduitry avatar Mar 02 '22 20:03 Conduitry

I did, yeah — closed by accident. An outDir outside the project directory should work as long as you don't specify paths config, but we need to address that case before we can consider this fully closed

Rich-Harris avatar Mar 02 '22 20:03 Rich-Harris

An outDir outside the project directory should work as long as you don't specify paths config,

FYI it doesn't work for me, with this config

import adapter from "@sveltejs/adapter-static";
import { mdsvex } from "mdsvex";

/** @type {import('@sveltejs/kit').Config} */
const config = {
  kit: {
    adapter: adapter(),
    prerender: { default: true },
   // either will cause the same error
    outDir: "/an/absolute/pat",
    outDir: "../a/relative/pat",
  },

  extensions: [".svelte", ".md"],

  preprocess: [
    mdsvex({
      extensions: [".md"],
      layout: {
        blog: "src/routes/blog/_post.svelte",
      },
    }),
  ],
};

export default config;

it throws a warning, runs for a bit, then dies with

# throws a warning
Your jsconfig.json should extend the configuration generated by SvelteKit:

# runs for a bit
...

# finally dies with
...
import { c as create_ssr_component, s as setContext, v as validate_component, m as missing_component } from "./chunks/index-7b568795.js";
^^^^^^

SyntaxError: Cannot use import statement outside a module

gotofritz avatar Apr 30 '22 22:04 gotofritz

I'm also getting Your jsconfig.json should extend the configuration generated by SvelteKit: in my console now and this is the ONLY result on google lol...

justingolden21 avatar May 06 '22 07:05 justingolden21

Getting the same error as reported by @gotofritz when setting the outDir outside the project root.

I guess a possible workaround for now would be to extend the build command under the package.json scripts by some commands that simulate the behaviour of a different output directory.

E.g. directly move the output after the build with something like:

rm -rf ../custom/outside/out/* && mv build/* ../custom/outside/out/ && rm -rf build

Which clears the output directory, moves over all build files and then removes the real build folder.

devidw avatar Sep 20 '22 11:09 devidw

Another nice feature would be a configurable production "build" output directory

pine3ree avatar Nov 29 '22 21:11 pine3ree

Oh thank you @babichjacob, so it was a static-adapter option. My mind was set to find a vite option for that...and was blind to the real solution. Kind regards.

pine3ree avatar Nov 30 '22 10:11 pine3ree

Is this still not resolved, because the docs said it should work but the link to outDir documentation 404s on me?

I'm guessing @flcarre & @devidw solutions are still the winners until this becomes more priority?

I will say the svelte and Vite config files have multiple output directory properties and none of them work when you try it which is extremely frustrating for new comers.

CodeBradley avatar Nov 03 '23 07:11 CodeBradley

Thanks, it works.

image

https://github.com/terwer/siyuan-plugin-publisher/blob/next/apps/publisher-app/svelte.config.js#L43

terwer avatar Nov 03 '23 10:11 terwer

Is this still not resolved, because the docs said it should work but the link to outDir documentation 404s on me?

I'm guessing @flcarre & @devidw solutions are still the winners until this becomes more priority?

I will say the svelte and Vite config files have multiple output directory properties and none of them work when you try it which is extremely frustrating for new comers.

https://kit.svelte.dev/docs/configuration#outdir

The outDir config option here is a special directory that SvelteKit writes temporary files to, needed when running the development server and while building for production. It is not the same as Vite's outDir config option which specifies the location of the build output. SvelteKit overrides the Vite outDir option because it needs to run two intermediary Vite builds: the client build and the server build. It writes to .svelte-kit/output/client and .svelte-kit/output/server. These are then used by your chosen adapter to finalise your build.

If you are looking to change where your final build is output to, see the adapter-node and adapter-static config options. https://kit.svelte.dev/docs/adapter-node#options https://kit.svelte.dev/docs/adapter-static#options

eltigerchino avatar Nov 03 '23 16:11 eltigerchino