Skip to content

Respect build.copyPublicDir config supplied by user #12432

@hyunbinseo

Description

@hyunbinseo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions