Skip to content

Commit

Permalink
fix: css resolving issue (#1834)
Browse files Browse the repository at this point in the history
  • Loading branch information
wre232114 authored Oct 27, 2024
1 parent 3651244 commit b3a7caf
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-candles-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farmfe/core": patch
---

fix css url resolving issue
2 changes: 2 additions & 0 deletions .github/workflows/rust-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ jobs:
osx-version: '12.3'
- uses: goto-bus-stop/setup-zig@v2
if: ${{ matrix.settings.zig }}
with:
version: 0.14.0-dev.1983+6bf52b050
- name: Build in docker
uses: addnab/docker-run-action@v3
if: ${{ matrix.settings.docker }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//foo-276e63.txt:
//foo-276e63.txt?url:
foo

//index.js:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//foo_bar-47689c.txt:
//foo_bar-47689c.txt?url:
foo_bar

//index.js:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//bar-a57e94.txt:
//bar-a57e94.txt?url:
bar

//foo-8bdf4c.txt:
//foo-8bdf4c.txt?url:
foo

//index.js:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//foo-8bdf4c.txt:
//foo-8bdf4c.txt?url:
foo

//index.js:
Expand Down
6 changes: 1 addition & 5 deletions crates/plugin_static_assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ impl FarmPluginStaticAssets {
)
}
}

fn remove_resource_name_query(name: &str) -> String {
name.split('?').next().unwrap_or(name).to_string()
}
}

impl Plugin for FarmPluginStaticAssets {
Expand Down Expand Up @@ -255,7 +251,7 @@ impl Plugin for FarmPluginStaticAssets {

context.emit_file(EmitFileParams {
resolved_path: param.module_id.clone(),
name: Self::remove_resource_name_query(&resource_name),
name: resource_name,
content: bytes,
resource_type: ResourceType::Asset(ext.to_string()),
});
Expand Down
2 changes: 1 addition & 1 deletion crates/toolkit/src/css/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn parse_css_stylesheet(
// 1. replace --: '' to --farm-empty: ''
let mut content = orig_content.replace("--:", "--farm-empty:");
// 2. replace filter: xxx.Microsoft.xxx to filter: "xxx.Microsoft.xxx" using regex. fix #1557
let regex = Regex::new(r#"filter:\s*(.*?)\.Microsoft\.(.*?)(;|\})"#).unwrap();
let regex = Regex::new(r#"filter:\s*([^'"]*?)\.Microsoft\.(.*?)(;|\})"#).unwrap();
content = regex
.replace_all(&content, "filter:\"$1.Microsoft.$2\"$3")
.to_string();
Expand Down
1 change: 1 addition & 0 deletions examples/css-url/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"clsx": "^1.2.1",
"core-js": "^3.30.1",
"font-awesome": "^4.7.0",
"react": "18",
"react-dom": "18"
},
Expand Down
2 changes: 2 additions & 0 deletions examples/css-url/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import 'font-awesome/css/font-awesome.css'
import './main.css';

import('./dynamic.css');
Expand All @@ -7,6 +8,7 @@ export function Main() {
return (
<>
<div className={'main'}>
<div className='fa fa-search'></div>
main
</div>
<div className={'main-2'}>
Expand Down
17 changes: 11 additions & 6 deletions pnpm-lock.yaml

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

0 comments on commit b3a7caf

Please sign in to comment.