sveltejs / sveltejs/kit

Respect `build.copyPublicDir` config supplied by user

Open
#12,432 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

vite
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

Background

We have a Node.js project where the /static directory is over 1GB in size.

In production, this directory is served using NGINX.

It does not have to be included in the SvelteKit build.

We keep the copy of the files in /static purely for the development server.

Problem

Current version does not respect the user provided build.copyPublicDir config.

https://github.com/sveltejs/kit/blob/%40sveltejs/kit%402.5.18/packages/kit/src/exports/vite/index.js#L614

// vite.config.ts

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';

export default defineConfig({
  build: { copyPublicDir: false }, // This has no impact.
  plugins: [sveltekit()]
});
Workaround
// svelte.config.js

import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import { randomUUID } from 'node:crypto';
import { env } from 'node:process';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: vitePreprocess(),
  kit: {
    adapter: adapter(),
    files: { assets: env.NODE_ENV === 'development' ? 'static' : randomUUID() }
  }
};

export default config;

Describe the proposed solution

Respect build.copyPublicDir, similar to the following PR:

Alternatives considered

  • Show warning that the build.copyPublicDir option has been overridden.
  • Provide this as an option for the Node.js adapter.

Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/kit/src/exports/vite/index.js around the build configuration handling referenced in the issue, then compare the intended behavior with pull request #11688. Confirm how the user-provided build.copyPublicDir value is currently overridden and consider the issue complete when false is respected without requiring the svelte.config.js workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, vite
Domain
build-system, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.