Comments (13)
Hi @nightire — in short, it's not possible (by design) to exclude certain directories, and you can check out #41 for some more details on that. I'd recommend using a custom extension (like .module.css
) for your modules if you want to exclude all other files.
Note also that by using a plugin like postcss-nested, you have the option of excluding individual files by writing something like:
:global {
.some-selector {
/* ... */
}
/* ... */
}
Depending on exactly how many files you're wanting to exclude, one or the other of those approaches might be more palatable. Does either one seem like it might accomplish what you're after?
from ember-css-modules.
OK, thanks for your suggestion.
What we want is to write some global themes, we might have many themes, but our app only load one of them depending on user preference. Both themes have same selectors, but different rules, so we need to compile them into separate files. That's why we need to exclude some of .css
files from ember-css-modules.
Let's say, if we use other pre-processors to write our themes, like less or sass, do they work well with ember-css-modules together?
from ember-css-modules.
You can configure ember-css-modules to emit its output into an intermediate file for other preprocessors to consume — see this section of the README for details.
Depending on how complex your themes are, you might also look at ember-css-modules's notion of "virtual modules", which basically let you configure @value
s as part of your build configuration.
from ember-css-modules.
Oh, I think there might be some misunderstandings, let me be more specific.
- By using ember-css-modules, we will get a
app-name.css
file finally, that includes all styles inapp/
directory. This is good for us, nothing needs to change. - Then, we need to write some themes, each theme has to be an individual file, because they both have same global selectors, out app will load one of them each time depending on user's preference.
So, if I understand it correctly, even we send app-name.scss
as intermediate file to ember-cli-sass, it still mixed many themes with main stylesheet, how is this possibly separate those themes into many individual files?
Virtual module is a really good thing, we've used it for all projects, but it only can help us write styles dynamically, but user choose different themes needs themes been existed first, I don't think virtual modules can help us in this situation, unless they can be used in runtime, like less did.
from ember-css-modules.
I think I get what I was misunderstanding before—so you want the end user to be able to switch between themes at runtime?
Since your goal is to work with global classes anyway, I think your best bet is probably to use ember-css-modules in concert with another addon like ember-cli-sass which has support for multiple output files.
If you set your intermediateOutputPath
for ember-css-modules to app/styles/app.scss
, ember-cli-sass should pass it straight through to produce app-name.css
. Then for each theme you write, you can configure an additional output path for ember-cli-sass. Since your themes will have a different extension (.scss
), ember-css-modules will ignore them.
The ergonomics of writing your main styling with CSS modules and your themes with vanilla SCSS might be a little odd, but that's the simplest path forward I can see right now. What do you think?
from ember-css-modules.
@dfreeman Yes, a little odd, but we can live with that, thank you very much, now I'm confident to finish our job!
from ember-css-modules.
@nightire Is there anything that still needs to happen here, or should this be closed out?
from ember-css-modules.
@dfreeman Yes I'm fine, Thank you very much.
from ember-css-modules.
I know this issue is closed, but I had a similar use case that I was able to solve quite simply and it might help others. My use case differed in that I was able to choose the theme at build time. In my index.html file I added a line under the css file specific to my app.
<link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link rel="stylesheet" href="{{rootURL}}assets/my-app-name.css">
<link rel="stylesheet" href="{{rootURL}}assets/theme.css">
Next, in ember-cli-build.js I did added my theme like this:
if (theme === 'light') {
app.import("vendor/light-theme.css", { outputFile: 'assets/theme.css' });
} else {
app.import("vendor/dark-theme.css", { outputFile: 'assets/theme.css' });
}
from ember-css-modules.
@brianhjelle Yes, we have tried this as well, but you can't let ECM to process styles in vendor
folder, right?
We ended up by implementing a more complex solution, build a tree of themes/**.css
, processing with a set of postcss plugins, merged with application's styleTree.
from ember-css-modules.
I'm doing dynamic / runtime themes with css vars, if that's an approach you want to go down. I have a global class that's just a bunch of var overrides
from ember-css-modules.
For the record: Can I use CSS Variables (Custom Properties)
There is no support for Internet Explorer.
from ember-css-modules.
@buschtoens Yes, this is the main reason we can't rely on Custom Properties yet.
from ember-css-modules.
Related Issues (20)
- Is there a codemod to colocate CSS modules with their components? HOT 2
- Turn off `Component.reopen()` call
- Deprecation use of Reopening the Ember.Component super class HOT 2
- Why we don't have tests that covers `Ember Engines`
- Incompatible with `postcss-nested` 5+ HOT 2
- Not compatible with Ember 4 HOT 3
- Question: How to use it on Ember Engines HOT 1
- Doesn't work with `ember-cli-sass`
- css file hash doesn't use correct path when generating-scoped-name in embroider app build, when consuming an addon using ecm HOT 1
- Provide exclude glob option HOT 1
- Tree passed to preprocessors for app and addon is not scoped with moduleName
- Replace local-class with class at build time instead of runtime HOT 2
- Question: How to use it with v2 addon? HOT 1
- Documenting migration from global app.css to css-modules
- pod route template: using `local-class` throws error HOT 1
- how to disable shipping JS modules?
- Usage in addons + Embroider build
- Heroku build got stuck in 1.6.2
- vendor files imported via postcss-import not being recompiled on change.
- Support for ember-template-imports? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-css-modules.