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 Modules doesn't get inserted in the build output #73
Comments
Strangely, I can't reproduce this locally, only on StackBlitz. Vite does add additional |
Also, there is already an e2e test for this that runs both dev and prod modes: https://github.com/tajo/ladle/tree/master/tests/css |
I've cloned your repo locally, and the tests does fail in the production - script There's the output
|
The only difference is that I use pnpm instead of npm; I am unsure if this matters. P.S. I'd be happy to help investigate this issue more. However, I need help finding a part responsible for loading CSS modules in the codebase. |
I ran into the same issue (MyCSSModule.123.css not being included in prod build) and also tried to run the tests from This fails for me:
While this does not fail:
Looks like npm install (not recognizing yarn.lock) resolves in a slightly different dependency tree, which then produces a different build. 🤯 |
I'm having the same issue. Reinstalling with yarn did not work for me either. The styles work fine in dev mode, but after build they are not included. Classnames are set correctly though. |
Having the same issue here... Tried to dig deeper into ladle's dependencies but weirdly, I have inconsistent results, sometimes it inject the CSS, sometimes it doesn't 🤷🏻 Here's a quick & dirty fix if anyone's interested: // inject-css.js
const fs = require('fs');
const path = require('path');
const { parse } = require('node-html-parser');
const fg = require('fast-glob');
function getCssFilesPath() {
return fg.sync(['./build/assets/**.css']).map((filePath) => filePath.replace(/^.\/build/gi, ''));
}
async function appendCssToHtml(html) {
const root = parse(html);
const cssPaths = getCssFilesPath();
const documentHead = root.querySelector('head');
if (documentHead) {
const links = [];
for (let index = 0; index < cssPaths.length; index += 1) {
const cssPath = cssPaths[index];
links.push(`<link rel="stylesheet" href="${cssPath}" />`);
}
// For some reason appendChild doesn't work, using the `set_content` API from `node-html-parser` instead:
documentHead.set_content(
`${documentHead.toString().replace(/\<\/head\>|\<head\>/, '')}
${links.toString().replace(/,/g, '')}`
);
}
// Replace index.html with the new css files
fs.writeFileSync(path.join(__dirname, './build/index.html'), root.toString());
}
const ladleHtmlFile = fs.readFileSync(path.join(__dirname, './build/index.html'), 'utf8');
appendCssToHtml(ladleHtmlFile); {
"scripts": {
"dev": "ladle serve --open=none",
"build": "ladle build && yarn build:inject-css",
"build:inject-css": "node inject-css.js"
},
} |
I am trying to reproduce this locally and remotely (stackblitz) with v0.15.1 using npm, yarn, pnpm... no luck. Can anyone else verify it's still happening with the latest version? There were some significant vite updates since then so it might got fixed? If not, I'll close this in a week. |
@tajo Can confirm it works for me now with vite |
Same! Using ladle 0.15.1 |
Great. Closing this. |
Problem description
CSS modules don't get inserted in the final build output (with
ladle build
).Reproduction code
https://stackblitz.com/edit/ladle-nmhbpc
Short instructions and observations
✅ Using
npm run dev
(ladle serve
), you can see the code working as excepted.Tested with
*.css
and*.scss
file extension.❌ Using
npm run build & npm run serve
, the CSS modules don't work.The output file
./build/assets/basic.stories.<hash_id>.css
aren't being included at all, anywhere. I was excepting to see it being included in the<head>
tag.On the other hand, the JS module
./build/assets/basic.stories.<hash_id>.js
do have correct generated CSS module assigned to the components propertyclassName
.The text was updated successfully, but these errors were encountered: