-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add assets mode for asset path generate (#1852)
* feat: add assets mode for asset path generate * test: update test failed
- Loading branch information
1 parent
92ce692
commit 3651244
Showing
19 changed files
with
156 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@farmfe/core": patch | ||
--- | ||
|
||
add assets mode for asset path generate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::TargetEnv; | ||
|
||
#[derive(Debug, Copy, Clone, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum AssetFormatMode { | ||
Node, | ||
Browser, | ||
} | ||
|
||
impl From<TargetEnv> for AssetFormatMode { | ||
fn from(value: TargetEnv) -> Self { | ||
if value.is_browser() { | ||
AssetFormatMode::Browser | ||
} else { | ||
AssetFormatMode::Node | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Default, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase", default)] | ||
pub struct AssetsConfig { | ||
pub include: Vec<String>, | ||
/// Used internally, this option will be not exposed to user. | ||
pub public_dir: Option<String>, | ||
// TODO: v2 | ||
// for ssr mode, should specify asset path format, default from `output.targetEnv` | ||
// pub mode: Option<AssetFormatMode>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module "*.png" { | ||
declare const v: string; | ||
export default v; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/core/src/config/normalize-config/normalize-asset.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CUSTOM_KEYS } from '../constants.js'; | ||
import { ResolvedCompilation, UserConfig } from '../types.js'; | ||
|
||
export function normalizeAsset( | ||
config: UserConfig, | ||
resolvedCompilation: ResolvedCompilation | ||
) { | ||
if (config.compilation?.assets?.mode) { | ||
const mode = config.compilation.assets.mode; | ||
|
||
// biome-ignore lint/style/noNonNullAssertion: <explanation> | ||
resolvedCompilation.custom![CUSTOM_KEYS.assets_mode] = JSON.stringify(mode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ export default defineConfig({ | |
environment: 'node', | ||
deps: { | ||
interopDefault: false | ||
} | ||
}, | ||
retry: 5 | ||
} | ||
}); |