Skip to content
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

Lightningcss proof of concept #23

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
455 changes: 452 additions & 3 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ prisma_client = { workspace = true }
prisma-client-rust = { workspace = true }
serde = { workspace = true }
tokio = { workspace = true }
lightningcss = { version = "1.0.0-alpha.44", features = ["browserslist"] }
28 changes: 28 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum Commands {
UserAdd(UserAddArgs),
SettingsInit,
Migrate,
Css,
}

#[derive(Args)]
Expand All @@ -39,6 +40,33 @@ async fn main() {
prisma_client._db_push(false).await.unwrap();

match &cli.command {
Commands::Css => {
use lightningcss::{
bundler::{Bundler, FileProvider},
stylesheet::{ParserFlags, ParserOptions, PrinterOptions},
targets::Targets,
};
use std::{fs::File, io::prelude::*, path::Path};

let fs = FileProvider::new();
let parser_options = ParserOptions {
flags: ParserFlags::NESTING | ParserFlags::CUSTOM_MEDIA,
..ParserOptions::default()
};
let mut bundler = Bundler::new(&fs, None, parser_options);
let stylesheet = bundler.bundle(Path::new("./style/main.css")).unwrap();
let options = PrinterOptions::<'_> {
targets: Targets::default(),
// targets: Targets::from(Browsers::default()),
minify: true,
..Default::default()
};
let style_output = stylesheet.to_css(options).unwrap();
let bytes = style_output.code.as_bytes();
let mut buffer = File::create("./style/main-bundle.css").unwrap();
buffer.write(bytes).unwrap();
println!("Css success");
}
Commands::Migrate => {
prisma_client._migrate_deploy().await.unwrap();
println!("Migration success");
Expand Down
1 change: 1 addition & 0 deletions style/buttons.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions style/main-bundle.css

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions style/main.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@import "https://unpkg.com/open-props";
/* @import "https://unpkg.com/open-props";
@import "https://unpkg.com/open-props/normalize.min.css";
@import "https://unpkg.com/open-props/buttons.min.css";
@import "https://unpkg.com/open-props/buttons.min.css"; */
@import "./open-props.min.css";
@import "./normalize.min.css";
@import "./buttons.min.css";

/* https://caniuse.com/css-nesting */

Expand Down
1 change: 1 addition & 0 deletions style/normalize.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions style/open-props.min.css

Large diffs are not rendered by default.