-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Reduce 1.0.0 size (Remove, reduce CSS variables option) #3761
Comments
It's probably doable by not including any of the themes and creating your own. It's a bit tricky because you'd need to know which CSS variables to include yourself. Now that I think about it, creating a "lite" theme could be something of a solution. |
That would be interesting. I feel there is too much overhead. I would only like to have css variables for the parts that actually are variable and change (I assume mostly color). For example the new "gradient" colorpalettes take a lot of variable space (I commented out the digits in the sass file to exclude them), maybe they could be in a separate sass file, which can be excluded. Anyway, super nice job. |
I'm still figuring out how to remove css variables. I found a package to convert them to sass-variables (and then remove them). However the order of variables gives a issue. For css you can refer to a variable that is declared later, but for sass not. There are several cases where reference is made to "not declared" variables. I don't know if that needs to be fixed (and it might be really difficult), just figuring out a way to make some major savings in file size. |
Changed the title to better explain the context of my question. |
Yes, 1.0 is terrible, I have rolled back to 0.9.4. |
@E021ntox Well I could make major savings with postcss. My postcss.config.js:
My final Bulma 1.0.0 CSS was 52kb, the 0.9.4 version was 46kb. I think color contrast is a major improvement in 1.0.0, I don't know if the theme is backwards compatible. |
@kasperkamperman Could you please elaborate a bit on what is needed to make a custom Bulma build with your config? So far I've followed these steps and got the basic my-bulma-project.css build. What I need to add to the package.json to reproduce your setup? Unfortunately I'm not familiar with the Node.js tooling ecosystem |
Yes. I'm also not super familiar either, but I could make it happen. You have to install more package install --save-dev (although I think the --save-dev doesn't really matter (I'm not really into npm). My package.json looks like this:
You see I add purge-bulma, to run the postcss part. Although you could run it from the command-line to I think with the postcss cli. For example I now use Everytime you run postcss it runs what's in the postcss.config.js (which I shared above). You can comment out parts you don't use. I use below too customize bulma (no dark-mode, custom colors). I removed the bulma-- prefix from the css variables, although if you use postcss-variables-compress that is not needed (since they get compressed names anyway). For completeness below, my custom version to build bulma (my-bulma.scss). I removed dark-mode and new things as grid/skeleton. However if you use purge-css and you don't use it, all those classes will be removed anyway.
Hope this helps. |
Thanks @kasperkamperman.
|
@nioc To be honest, I just worked from the Bulma examples and tried to make it work. I hardly get SCSS either (and I'm too "lazy" to dive into it) :-) |
My understanding is:
As you In bulma docs, it is said that we can load all lib (bulma/sass) or load only what we need. But it does not matter, as you purge css 😄 |
Thanks for your help again @kasperkamperman and obviously @jgthms for this incredible work. /* eslint-disable @typescript-eslint/no-var-requires */
const purgecss = require('@fullhuman/postcss-purgecss')
module.exports = {
plugins: [
purgecss({
content: [
'./index.html',
'./src/**/*.{svelte,js,ts}',
], // declaring source files
safelist: {
standard: [/$svelte-/], // required for inline component styles
},
variables: true, // remove unused CSS variables
}),
],
} I do not use
So 107 kB (60 kB gzipped), for such a rich CSS with 2 themes, that's impressive 🦸🏻 |
Great find. Thanks @nioc. I'll see if I can include |
same, rolledback to 0.9.4 due to bundle size ... |
@nioc: How did you instruct system "purgecss",
"--css", "_build/css/base.css",
"--content", "_tmp/compiled.html.erb",
"--safelist", "theme-dark",
"--safelist", "fa-*",
"--output", "_build/css" |
Hello @muellerj I'm not behind my pc but I think themes are also purged, but it's what I wanted (keep only used variables and classes, and in my case I use both light and dark in a svelte app). |
Understood - thanks. If I find a configuration that keeps the themes, I'll post it here. My feeling is that the CLI interface for |
If anyone stumbles across this - I ended up using the inline CSS comments to guard the themes from being purged. In ruby, it looks something like this: def add_purgecss_protection(file)
return if has_purgecss_protection?(file)
puts "Adding protection to #{file}"
File.write(file, [
"/*! purgecss start ignore */",
*File.readlines(file).map(&:chomp),
"/*! purgecss end ignore */",
].join("\n"))
end
def has_purgecss_protection?(file)
lines = File.readlines(file)
return false unless lines.first.chomp == "/*! purgecss start ignore */"
return false unless lines.last.chomp == "/*! purgecss end ignore */"
true
end
# ...
add_purgecss_protection("_src/bulma/sass/themes/_index.scss") # <= This guards themes/_index.scss from being purged
system "sass", "sass/base.scss", "_build/css/base.css"
system "purgecss",
"--css", "_build/css/tc-base.css",
"--content", "_tmp/compiled.html.erb",
"--output", "_build/css"
system "csso", "_build/css/base.css",
"--output", "_build/css/base.css" |
This is a question.
Overview of the problem
This is about the Bulma CSS framework
I'm using Bulma version [1.0.0]
I am sure this issue is not a duplicate
Description
I love the new Bulma and the accessible color styles. What I love less is the new file size.
The default minified went from 207kb to 554kb.
This is mainly do addition from the css variables. This is nice of for color switching, but I feel it's not worth the trade-off for my current sites.
Is there away to compile without variables in Sass. I tried postprocessing with postcss, but that plugin hangs on the Bulma script.
I posted an issue on that here: MadLittleMods/postcss-css-variables#139
I'm curious to know if there are other ways.
I use other postcss plugins to prune unused variables and compress variables names (not nice for readibility, but regular site-users won't care. I also changed the prefix to one character (instead of bulma- in front of each variable).
Any suggestions or ideas are welcome.
The text was updated successfully, but these errors were encountered: