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

Disabling cssCodeSplit breaks CSS file location used by tag helper in Rails #434

Open
iamdriz opened this issue Feb 12, 2024 · 1 comment
Labels
bug: pending triage Something doesn't seem to be working, but hasn't been verified

Comments

@iamdriz
Copy link

iamdriz commented Feb 12, 2024

Setting cssCodeSplit (https://vitejs.dev/config/build-options#build-csscodesplit) to false in order to create a single CSS file as per the documentation: "If disabled, all CSS in the entire project will be extracted into a single CSS file." causes Vite to create two files if we have app/javascript/entrypoints/style.scss:

style-P1uBkUvy.css  style-w40geAFS.js

The tag helper used to render this stylesheet in the view:

<%= vite_stylesheet_tag 'style.scss', media: 'all', 'data-turbo-track': 'reload' %>

Renders (a non existent file reference, see the .js.css extension):

<link rel="stylesheet" media="all" href="/vite/assets/style-w40geAFS.js.css" data-turbo-track="reload" />

Instead of:

<link rel="stylesheet" media="all" href="/vite/assets/style-P1uBkUvy.css" data-turbo-track="reload" />

Setting cssCodeSplit to true fixes this, but means any CSS imported into JS files will no longer be combined with the main CSS file. Making this setting fragile in the case of this plugin. Is it possible to allow this setting to be able to be set to false without it breaking the tag helper and pointing to the wrong file?

Environment:

bin/vite present?: true
vite_ruby: 3.5.0
vite_rails: 3.0.17
rails: 6.1.7.6
node: v18.13.0
npm: 8.19.3
yarn: 1.22.17
pnpm: 8.10.5
ruby: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]

├─┬ @vitejs/plugin-react@4.2.1
│ └── vite@5.0.12 deduped
├─┬ vite-plugin-ruby@5.0.0
│ └── vite@5.0.12 deduped
└── vite@5.0.12
@iamdriz iamdriz added the bug: pending triage Something doesn't seem to be working, but hasn't been verified label Feb 12, 2024
@ElMassimo
Copy link
Owner

Hi Cameron!

Have you tried this suggestion from the Troubleshooting guide?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: pending triage Something doesn't seem to be working, but hasn't been verified
Projects
None yet
Development

No branches or pull requests

2 participants