Skip to content

Bundler: Support CSS Modules *.module.css #16916

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

Closed
nicksrandall opened this issue Jan 30, 2025 · 7 comments · Fixed by #17958
Closed

Bundler: Support CSS Modules *.module.css #16916

nicksrandall opened this issue Jan 30, 2025 · 7 comments · Fixed by #17958
Assignees
Labels
bundler Something to do with the bundler css CSS parser, bundler-related enhancement New feature or request

Comments

@nicksrandall
Copy link

What is the problem this feature would solve?

I love Bun's ethos to be a one-stop-shop for all developer/tooling needs. I'd like to use Bun's Bundler to bundle reusable components. While Bun's Bundler has support for bundling CSS, the lack of CSS Modules support make it much harder to share (or embed) these components because of the likelihood that the styles (CSS) could clash with other styles on the page.

What is the feature you are proposing to solve the problem?

CSS Modules is a simple, yet extremely useful tool that automatically hashes your css selectors so that they will not collide with other styles (from other sources) on your page and then provides those hashed names for you in the form on a javascript import so that the ergonomics remain. This is essential for may use-cases involving the re-use styles (or components) across apps.

More info: https://github.com/css-modules/css-modules

Notes

What alternatives have you considered?

  • A bun-lightningcss plugin would probably work -- similar to bun's tailwind support.
@nicksrandall nicksrandall added the enhancement New feature or request label Jan 30, 2025
@RiskyMH RiskyMH added the bundler Something to do with the bundler label Jan 31, 2025
@EvHaus
Copy link

EvHaus commented Feb 22, 2025

Bun 1.2.3 recently also launched support for developing frontend apps using Bun.serve(). Could this ticket be expanded to add support for CSS Modules there as well (not just the bundler)? At the moment, if you try to import a CSS Module file like this:

import styles from './App.module.css';

console.log(styles.main);

Bun fails with:

TypeError: Cannot read properties of undefined (reading 'main')

EvHaus added a commit to EvHaus/pragmatic-drag-and-drop-tree that referenced this issue Feb 22, 2025
EvHaus added a commit to EvHaus/pragmatic-drag-and-drop-tree that referenced this issue Feb 22, 2025
@RiskyMH RiskyMH added the css CSS parser, bundler-related label Feb 24, 2025
@zackradisic zackradisic self-assigned this Feb 26, 2025
@marcospgp
Copy link

CSS module support would be great, or at least documenting how we can add it using third party tools

frontend dev with bun has gotten 100x better with the support of targeting .html files, this would be the final step towards a production ready solution

@zackradisic
Copy link
Member

I am currently working on this!

@nicksrandall
Copy link
Author

@zackradisic I see that this issue was closed without supporting :global(.selector) syntax. IMO, that is an important feature. Should I create a new issue to support that part of css-modules?

EvHaus added a commit to EvHaus/pragmatic-drag-and-drop-tree that referenced this issue Mar 11, 2025
EvHaus added a commit to EvHaus/pragmatic-drag-and-drop-tree that referenced this issue Mar 11, 2025
EvHaus added a commit to EvHaus/pragmatic-drag-and-drop-tree that referenced this issue Mar 11, 2025
EvHaus added a commit to EvHaus/pragmatic-drag-and-drop-tree that referenced this issue Mar 11, 2025
@EvHaus
Copy link

EvHaus commented Mar 11, 2025

This doesn't seem to work for me in 1.2.5. This code:

import { serve } from 'bun';
import index from './index.html';

const server = serve({
	development: process.env.NODE_ENV !== 'production',
	routes: {
		'/*': index,
	},
});

when run, throws:

frontend ReferenceError: import_App_module is not defined
      at App (/Users/evhaus/Git/pragmatic-drag-and-drop-tree/examples/App.tsx:8:19)

Image

@gland2015
Copy link

By the way, support SCSS

@gland2015
Copy link

We can first utilize the existing ecosystem and come up with feasible solutions, and then optimize them for better results in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bundler Something to do with the bundler css CSS parser, bundler-related enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants