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
Replacement is mixing up variables #34
Comments
@ericchernuka Can you share the :root as well. It will better help me understand if there is an issue. |
@navanshu I've updated my description with a more clear delineation between the As for the PostCSS config, I'm actually just using Vite's built-in config with SCSS/SASS modules. https://vitejs.dev/config/#css-postcss So my config looks like the following: import { defineConfig } from 'vite';
import reactRefresh from '@vitejs/plugin-react-refresh';
// https://vitejs.dev/config/
export default defineConfig({
// This changes the out put dir from dist to build
// comment this out if that isn't relevant for your project
build: {
outDir: 'build',
},
plugins: [reactRefresh()],
css: {
postcss: {
plugins: [require('postcss-variable-compress')]
}
}
}); |
@ericchernuka I am going to need the output root of your code, since I ran the code https://runkit.com/navanshu/ericchernuka-test and it works fine. Share more code that can be relevant to this.
|
@navanshu Hmm. that's interesting. I used your runkit and experimented and it looks correct. I'll dig into my pipeline a bit more as something must unexpected must be occurring during the transformation from SCSS modules to the final CSS. |
As I investigate this, I replicated the plugin code so I could log out what it's matching. The additional code I added was the following:
Here is the output from that: https://gist.github.com/ericchernuka/ccadff3b929e477ebd4722a23e822b99 It's almost like the map is reset. I wonder if its a combination of SCSS modules/Vite as the build pipeline, but I haven't come to an insights yet. |
@navanshu I created a reproducible environment where you can see the output I'm seeing. https://stackblitz.com/edit/vitejs-vite-bezk8w?file=src%2FButton.module.scss&terminal=dev |
@ericchernuka The map will get reset if postcss is reinitialised or if the files postcss watching is changed, if the order of variables initialisation doesn't change the short names variable get will be same. The thing that might be getting wrong is You are maybe not importing the scss files correctly
|
@ericchernuka Check here https://stackblitz.com/edit/vitejs-vite-adhamz?file=src/Button.tsx. I made some changes to your code. Unfortunately for now the plugins is not made to be able to replace the variable consistently accross different css files. |
Understood. The only way I can make that happen is by running this as an after-build step then as using SCSS modules avoids me knowing them upfront. I'll have to look at an alternative for now I guess. Really awesome idea though. In my tests, it reduced our bundle size by 28% just by performing this replacement. |
@ericchernuka Thanks I would suggest you write you css in js. Generaly I don't recommend my module as their is GZIP to take of bundle size when the file is one. But I can see when their are multiple files, GZIP will fail. I will put an update to solve this issue. |
@ericchernuka I have made a seprate project for what you are looking for you can track its progress at https://github.com/Febnik/vitecss-variable-compress |
Amazing! Thank you! |
@ericchernuka Hi
|
@navanshu Amazing! I'll try and find some time next week to integrate it. Thanks so much. My prelim tests showed a ~30% reduction in CSS bundle size so I can't wait to utilize this. |
@ericchernuka I am happy that it is helpful, to be true I made it, but has not had the time to really use it. |
I believe vite is the best SPA solution offered today. 0 complaints. |
Okay, I kind of dislike being limited by the functionality of a tool I am using. |
I'm a product developer, so if the tooling can do a large amount of the lifting without configuration and I can focus on building great product features, then I'm all for it. Vite is just a breath of fresh air from the speed and ease of configuration if you need to bail out to rollup plugins (which I rarely have had to do). Worth a shot at least. |
Understood. |
I just tried this plugin out, but I'm getting weird behaviour where variables which are numbers and units are being replaced with colours. I've provided an example below. Any thoughts?
The text was updated successfully, but these errors were encountered: