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

CSS file name changed after v3 upgrade #9877

Closed
7 tasks done
IGx89 opened this issue Aug 28, 2022 · 6 comments · Fixed by #11578
Closed
7 tasks done

CSS file name changed after v3 upgrade #9877

IGx89 opened this issue Aug 28, 2022 · 6 comments · Fixed by #11578

Comments

@IGx89
Copy link

IGx89 commented Aug 28, 2022

Describe the bug

Hello! I have a pretty basic vite.config.ts. Main area of interest is this:

  build: {
    rollupOptions: {
      input: {
        "my-app": resolve(__dirname, "index.html"),
      },
    }
  }

With Vite 2.x, it would produce this output:

dist/index.html
dist/assets/my-app.<hash>.css
dist/assets/my-app.<hash>.js

After upgrading to Vite 3 it changed to this:

dist/index.html
dist/assets/index.<hash>.css
dist/assets/my-app.<hash>.js

Is that change intentional? Is there an easy way to get this behavior back, beyond adding a hack in assetFileNames?

Thanks!

Reproduction

https://stackblitz.com/edit/vitejs-vite-r2ykgd?file=vite.config.js

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (4) x64 Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz
    Memory: 5.73 GB / 23.84 GB
  Binaries:
    Node: 16.14.2 - C:\Program Files\nodejs\node.EXE     
    npm: 8.5.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 104.0.5112.102
    Edge: Spartan (44.19041.1266.0), Chromium (104.0.1293.63)

Used Package Manager

npm

Logs

No response

Validations

@milahu
Copy link
Contributor

milahu commented Sep 10, 2022

this works for me, with vite v3.1.0

// vite.config.js

import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid"; // solidjs framework

const assetsDir = 'assets/';

const outputDefaults = {
  // remove hashes from filenames
  entryFileNames: `${assetsDir}[name].js`,
  chunkFileNames: `${assetsDir}[name].js`,
  assetFileNames: `${assetsDir}[name].[ext]`,
}

export default defineConfig({
  plugins: [
    solidPlugin(), // solidjs framework
  ],
  build: {
    target: "esnext",
    polyfillDynamicImport: false,
    //sourcemap: true,
    rollupOptions: {
      output: {
        ...outputDefaults,
      }
    },
  },
  worker: {
    rollupOptions: {
      output: {
        ...outputDefaults,
      }
    },
  },
});

example output

npm run build 

> vite-template-solid@0.0.0 build
> vite build

vite v3.1.0 building for production...
dist/assets/logo.svg            1.56 KiB
dist/assets/editor.worker.js    170.93 KiB
dist/index.html                 0.62 KiB
dist/assets/index.css           61.38 KiB / gzip: 10.88 KiB
dist/assets/index.js            2026.99 KiB / gzip: 529.85 KiB

when i remove worker.rollupOptions.output then i get, for example

dist/assets/editor.worker.b9a77fdc.js

but all the other filenames are ok

duplicate of #7613

@julien-fontaine
Copy link

I run into the same issue, and it ignores not only the file name, but also the specified path:

    build: {
        rollupOptions: {
            input: {
                'js/main.js': 'resources/js/app.js',
                'js/utils/my-util.js': 'resources/js/utils/my-util.js',
                'css/main.css': 'resources/sass/app.css',
                'css/utils/colors.css': 'resources/sass/utils/my-util.css',
            }
        }
    },

produces

dist/assets/js/main.<hash>.js
dist/assets/js/utils/my-util.<hash>.js
dist/assets/app.<hash>.css
dist/assets/my-util.<hash>.css

I would also like to highlight that this bug does not affect JavaScript file.
It still occurs in v3.1.1.

@ianwitherow
Copy link

Still have this problem; any update?

Built css files end up named "index-[hash].css" instead of using the [name].

@IGx89
Copy link
Author

IGx89 commented Jan 12, 2023

Still occurring in v4.0.4, FYI.

@oliveiracdz
Copy link

It seems that PR #9485 fixes this bug.

@julien-fontaine
Copy link

This issue also occurs when using the build.lib.entry config key, which is much more annoying. It removes (or merges?) files that have the same name, but are in different directories, from the dist directory.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants