vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
67.24k stars 6.05k forks source link

worker.rollupOptions.output does not control output directory bug has returned in v5.2.0 #17377

Closed mdaemon-technologies closed 3 months ago

mdaemon-technologies commented 3 months ago

Describe the bug

Specifying assetFileNamesand chunkFileNamesin worker.rollupOptions does not affect the worker's output directory.

I tested using the same stackblitz for v3, v4, v5. It does not appear to have ever been fixed, even though I found multiple closed duplicates.

Is there an additional library required?

Reproduction

https://stackblitz.com/edit/vitejs-vite-8bjpzf

Steps to reproduce

  1. open the reproduction link
  2. run npm run build

System Info

https://stackblitz.com/edit/vitejs-vite-8bjpzf

Used Package Manager

npm

Logs

vite.config.js
import { defineConfig } from 'vite';

export default defineConfig(({ command, mode }) => {
  return {
    worker: {
      rollupOptions: {
        output: {
          assetFileNames: 'worker/asset/[name].js',
          chunkFileNames: 'worker/chunk/[name].js',
        },
      },
    },
  };
});

image

Validations

stackblitz[bot] commented 3 months ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

sapphi-red commented 3 months ago

You need to set worker.rollupOptions.output.entryFileNames. https://stackblitz.com/edit/vitejs-vite-1irzjy?file=vite.config.js

mdaemon-technologies commented 3 months ago

That did work in the minimal reproduction. However, in my local build of 5.2.0 it did not work. What did work was moving the "worker" property above the "build" property in the vite.config.js file. Clearly, the location of the property should not matter.

before:

build: {
  rollupOptions: {
    output: {
      assetFileNames: "web/assets/[name]-[hash].[ext]",
      chunkFileNames: "web/assets/[name]-[hash].[ext]",
      entryFileNames: "web/assets/[name]-[hash].js"
    }
  }
},
worker: {
  format: "es",
  rollupOptions: {
    output: {
      entryFileNames: `web/workers/[name]-[hash].js`,
    }
  }
},

output:

dist/assets/myworker-dxgnPMyq.js

after

worker: {
  format: "es",
  rollupOptions: {
    output: {
      entryFileNames: `web/workers/[name]-[hash].js`,
    }
  }
},
build: {
  rollupOptions: {
    output: {
      assetFileNames: "web/assets/[name]-[hash].[ext]",
      chunkFileNames: "web/assets/[name]-[hash].[ext]",
      entryFileNames: "web/assets/[name]-[hash].js"
    }
  }
},

output:

dist/web/workers/myworker-rgRqI9cd.js