kit icon indicating copy to clipboard operation
kit copied to clipboard

Custom output rollup configuration is overhidden by the default configuration

Open edieval opened this issue 5 years ago • 10 comments

Describe the bug In the svelte configuration file when we try to set the assetFileNames or chunkFileNames in output rollup, this is overhidden by the default configuration

To Reproduce Set a assetFileNames in the rollup options and check the assets files.

Expected behavior The configuration set in the svelte configuration file must be used.

Information about your SvelteKit Installation: Next version: 103

Severity Blocking our usage of SvelteKit: declare static asset files in the micro-frontend application

Additional context This portion of code seems to be the origin of the issue: https://github.com/sveltejs/kit/blob/57efb032983a614462bae6b1d7496072b6aa8c96/packages/kit/src/core/build/index.js#L149

	rollupOptions: {
		...(user_config.build && user_config.build.rollupOptions),
		input,
		output: {
			entryFileNames: '[name]-[hash].js',
			chunkFileNames: 'chunks/[name]-[hash].js',
			assetFileNames: 'assets/[name]-[hash][extname]'
		},
		preserveEntrySignatures: 'strict'
	}
},

edieval avatar May 10 '21 15:05 edieval

Can you elaborate on why you need to customise these filenames?

Rich-Harris avatar May 10 '21 17:05 Rich-Harris

We need to register the assets in our micro-frontend application and it's easier with static file names. So, we tried to remove the hash and simplify paths.

But, well, It's more about the point that we can configure them in the svelte config file but the config is not applied than our usage. We can add a tool to change the file names after build.

edieval avatar May 11 '21 07:05 edieval

It sounds like what you really need is access to the manifest Vite generates linking source files to their built counterparts?

Rich-Harris avatar May 11 '21 15:05 Rich-Harris

Hello guys, it doesn't seem to be fixed with this issue #1572. I've just installed the last @next.132 version and I've this message during the build :

build_client: The value for kit.vite.build.rollupOptions.output.entryFileNames specified in svelte.config.js has been ignored. This option is controlled by SvelteKit.
 
build_client: The value for kit.vite.build.rollupOptions.output.chunkFileNames specified in svelte.config.js has been ignored. This option is controlled by SvelteKit.

build_client: The value for kit.vite.build.rollupOptions.output.assetFileNames specified in svelte.config.js has been ignored. This option is controlled by SvelteKit.

ThomasRumasLM avatar Jul 20 '21 09:07 ThomasRumasLM

Bump. I'd like to override the output configuration too.

mrrfv avatar Oct 28 '21 12:10 mrrfv

I was going to remove the hash in the filename to work around https://github.com/sveltejs/kit/issues/4528 by building index.html once, but this is in my way too.

If I can have static filenames in index.html (which fails to be generated b/c #4528) then I can work around the adapter bug.

DougAnderson444 avatar May 15 '22 19:05 DougAnderson444

I was able to achieve this by writing a Vite plugin, however it didn't work for assets. See this discussion.

raduab avatar Sep 28 '22 10:09 raduab

It would also be great if we could obfuscate filenames.

OwsOwies avatar Dec 30 '22 11:12 OwsOwies

Our project managed to serve two different files under the same name index.765Qou6w.js

Old version

import{s as t}from"./index.dfZDWpqj.js";import{r as m}from"./index.Rdu9h4Oq.js";function o(r,a){m(2,arguments);var e=t(r),i=t(a);return e.getTime()===i.getTime()}export{o as i};

New version

import{s as t}from"./index.dfZDWpqj.js";import{r as m}from"./index.hzUXFZFB.js";function o(r,a){m(2,arguments);var e=t(r),i=t(a);return e.getTime()===i.getTime()}export{o as i};

This issue leads to 500 error that are difficult to reproduce. The page loads, then the code attempts to import index.Rdu9h4Oq.js but the file does not exist which leads to the 500 internal error. The old version has been cached in the browser and we need to change the filenames so we can unblock our users. Ideally, we'd want to increase the length of the hash to reduce the likeliness of this happening again.

Thanks to @raduab we used the following to increase hash length

function hash() {
  return {
    name: "hash-plugin",
    apply: "build" as const,
    config(config) {
      config.build.rollupOptions.output.assetFileNames =
        config.build.rollupOptions.output.assetFileNames.replace("[hash]", `[hash:20]`);

      config.build.rollupOptions.output.chunkFileNames =
        config.build.rollupOptions.output.chunkFileNames.replace("[hash]", `[hash:20]`);

      config.build.rollupOptions.output.entryFileNames =
        config.build.rollupOptions.output.entryFileNames.replace("[hash]", `[hash:20]`);

      return config;
    }
  };
}

export default defineConfig({
  plugins: [viteCommonjs(), sveltekit(), hash()],
  //...

http-teapot avatar Jan 22 '25 05:01 http-teapot

Our project managed to serve two different files under the same name index.765Qou6w.js

Old version

import{s as t}from"./index.dfZDWpqj.js";import{r as m}from"./index.Rdu9h4Oq.js";function o(r,a){m(2,arguments);var e=t(r),i=t(a);return e.getTime()===i.getTime()}export{o as i};

New version

import{s as t}from"./index.dfZDWpqj.js";import{r as m}from"./index.hzUXFZFB.js";function o(r,a){m(2,arguments);var e=t(r),i=t(a);return e.getTime()===i.getTime()}export{o as i};

This issue leads to 500 error that are difficult to reproduce. The page loads, then the code attempts to import index.Rdu9h4Oq.js but the file does not exist which leads to the 500 internal error. The old version has been cached in the browser and we need to change the filenames so we can unblock our users. Ideally, we'd want to increase the length of the hash to reduce the likeliness of this happening again.

Thanks to @raduab we used the following to increase hash length

function hash() { return { name: "hash-plugin", apply: "build" as const, config(config) { config.build.rollupOptions.output.assetFileNames = config.build.rollupOptions.output.assetFileNames.replace("[hash]", [hash:20]);

  config.build.rollupOptions.output.chunkFileNames =
    config.build.rollupOptions.output.chunkFileNames.replace("[hash]", `[hash:20]`);

  config.build.rollupOptions.output.entryFileNames =
    config.build.rollupOptions.output.entryFileNames.replace("[hash]", `[hash:20]`);

  return config;
}

}; }

export default defineConfig({ plugins: [viteCommonjs(), sveltekit(), hash()], //...

@http-teapot thanks for sharing this, this was a great find, this is what I needed for the entryNames 🙏

og-neth avatar Mar 13 '25 20:03 og-neth