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

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

Open
ecstrema opened this issue Feb 22, 2022 · 18 comments
Open

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

ecstrema opened this issue Feb 22, 2022 · 18 comments
Labels
feature / enhancement New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc.
Milestone

Comments

@ecstrema
Copy link
Contributor

ecstrema commented Feb 22, 2022

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
Copy link
Contributor Author

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.

@bluwy bluwy added the feature / enhancement New feature or request label Feb 22, 2022
@Rich-Harris
Copy link
Member

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?

@ecstrema
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@Rich-Harris Rich-Harris mentioned this issue Mar 1, 2022
5 tasks
@flcarre
Copy link

flcarre commented Mar 1, 2022

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

@DominikPieper
Copy link

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

@flcarre
Copy link

flcarre commented Mar 1, 2022

Finaly found a workarround using adapter-static

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

@Conduitry
Copy link
Member

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

@Rich-Harris
Copy link
Member

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 Rich-Harris reopened this Mar 2, 2022
@gotofritz
Copy link

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

@justingolden21
Copy link

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...

@Rich-Harris Rich-Harris added this to the 1.0 milestone May 11, 2022
kodiakhq bot pushed a commit to vercel/turborepo that referenced this issue Jun 29, 2022
A basic svelte example. 

Replaces #1184 and #244

**NOTE**: There is no shared `ts-config` package here because of how svelte sets up it's ts-config inheritance. The base config is auto generated in a set location (`.svelte-kit`). There are a few open issues about adjusting this for better monorepo support (relevant issues: sveltejs/kit#4052, microsoft/TypeScript#29118 (comment))
@benmccann benmccann added the p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. label Jul 20, 2022
@Rich-Harris Rich-Harris modified the milestones: 1.0, whenever Jul 20, 2022
@devidw
Copy link

devidw commented Sep 20, 2022

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.

@pine3ree

This comment was marked as off-topic.

@babichjacob

This comment was marked as off-topic.

@pine3ree

This comment was marked as off-topic.

yeabu369 pushed a commit to yeabu369/afrovalleyio that referenced this issue Dec 31, 2022
A basic svelte example. 

Replaces vercel/turborepo#1184 and vercel/turborepo#244

**NOTE**: There is no shared `ts-config` package here because of how svelte sets up it's ts-config inheritance. The base config is auto generated in a set location (`.svelte-kit`). There are a few open issues about adjusting this for better monorepo support (relevant issues: sveltejs/kit#4052, microsoft/TypeScript#29118 (comment))
@CodeBradley
Copy link

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.

@terwer

This comment was marked as off-topic.

@eltigerchino
Copy link
Member

eltigerchino commented Nov 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc.
Projects
None yet
Development

No branches or pull requests