diff --git a/README.md b/README.md index bdfab30e9..3af5752c0 100644 --- a/README.md +++ b/README.md @@ -9,21 +9,19 @@ > Super fast web build engine written in rust. yet another performant alternative besides webpack/vite -|| Webpack | Vite | Farm | Compare | -|---| --- | --- | --- | --- | -|**cold start**| 853ms | 276ms | 67ms | Farm is faster: **12x webpack**,**4x vite** | -|**HMR**| 43ms | 23ms | 2ms | Farm is faster: **20x webpack**,**10x vite** | -|**onload**| 83ms | 310ms | 57ms | Farm is faster: **5x vite** | -|**accessible time**| 936ms | 586ms | 124ms | Farm is faster: **8x webpack**,**5x vite** | - +| | Webpack | Vite | Farm | Compare | +| ------------------- | ------- | ----- | ----- | --------------------------------------------- | +| **cold start** | 853ms | 276ms | 67ms | Farm is faster: **12x webpack**,**4x vite** | +| **HMR** | 43ms | 23ms | 2ms | Farm is faster: **20x webpack**,**10x vite** | +| **onload** | 83ms | 310ms | 57ms | Farm is faster: **5x vite** | +| **accessible time** | 936ms | 586ms | 124ms | Farm is faster: **8x webpack**,**5x vite** | > Test Repo:https://github.com/farm-fe/performance-compare -> +> > Test Machine(Linux Mint 21.1 Cinnamon, 11th Gen Intel© Core™ i5-11400 @ 2.60GHz × 6, 15.5 GiB)
- **Features**: - 🔥 **Super Fast**: Start a react / vue(incoming) project in milliseconds. @@ -44,22 +42,20 @@ ## Getting Started -Install Farm Cli: +Create a new Farm Project ```sh -npm install -g @farmfe/cli +npx @farmfe/cli@latest create ``` -We provided a experience react project for now. Using `farm create` to create a new project. Using `farm start` to start the project. +Start the project: ```sh -farm create && cd farm-react && npm i && npm start +cd farm-react && npm i && npm start ``` ## Configuring -> Official docs site is on the way... - Farm load configuration file from `farm.config.ts`. The available config as below: ```ts diff --git a/crates/compiler/src/generate/finalize_resources.rs b/crates/compiler/src/generate/finalize_resources.rs index 09bda9a5c..c4aca27c3 100644 --- a/crates/compiler/src/generate/finalize_resources.rs +++ b/crates/compiler/src/generate/finalize_resources.rs @@ -39,6 +39,7 @@ pub fn write_resources(context: &Arc) { } // Remove useless resources + // TODO support sub dir scene let existing_resources = read_dir(output_dir.clone()) .unwrap() .map(|entry| { diff --git a/crates/compiler/src/update/regenerate_resources.rs b/crates/compiler/src/update/regenerate_resources.rs index db90ac063..0f0c3cfd5 100644 --- a/crates/compiler/src/update/regenerate_resources.rs +++ b/crates/compiler/src/update/regenerate_resources.rs @@ -98,11 +98,12 @@ pub fn regenerate_resources_for_affected_module_groups( // also remove the related resources, the resources will be regenerated later let mut resource_maps = context.resources_map.lock(); let resource_pot = resource_pot_map.resource_pot_mut(resource_pot_id).unwrap(); - resource_pot.clear_resources(); for resource in resource_pot.resources() { resource_maps.remove(resource); } + + resource_pot.clear_resources(); } let resource_pots = resource_pot_map diff --git a/crates/plugin_css/src/lib.rs b/crates/plugin_css/src/lib.rs index a073e5e57..887fa86b5 100644 --- a/crates/plugin_css/src/lib.rs +++ b/crates/plugin_css/src/lib.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use farmfe_core::{ config::Config, context::CompilationContext, - module::{CssModuleMetaData, ModuleMetaData, ModuleType}, + module::{CssModuleMetaData, ModuleId, ModuleMetaData, ModuleType}, plugin::{ Plugin, PluginAnalyzeDepsHookParam, PluginHookContext, PluginLoadHookParam, PluginLoadHookResult, PluginParseHookParam, PluginTransformHookResult, @@ -28,6 +28,10 @@ impl Plugin for FarmPluginCss { fn name(&self) -> &str { "FarmPluginCss" } + /// This plugin should be executed at last + fn priority(&self) -> i32 { + 0 + } fn load( &self, @@ -61,6 +65,8 @@ impl Plugin for FarmPluginCss { if matches!(param.module_type, ModuleType::Css) && matches!(context.config.mode, farmfe_core::config::Mode::Development) { + let module_id = ModuleId::new(param.resolved_path, &context.config.root); + let css_js_code = format!( r#" const cssCode = `{}`; @@ -75,7 +81,8 @@ if (previousStyle) {{ document.head.appendChild(style); }} "#, - param.content, param.resolved_path + param.content, + module_id.to_string() ); Ok(Some(PluginTransformHookResult { diff --git a/crates/plugin_html/src/resources_injector.rs b/crates/plugin_html/src/resources_injector.rs index dc7f4340e..b744a73ee 100644 --- a/crates/plugin_html/src/resources_injector.rs +++ b/crates/plugin_html/src/resources_injector.rs @@ -94,11 +94,8 @@ impl ResourcesInjector { } } - dynamic_resources_code += &format!( - r#"'{}': [{}],"#, - module_id.id(self.mode.clone()), - resources_code - ); + let id = module_id.id(self.mode.clone()).replace(r"\", r"\\"); + dynamic_resources_code += &format!(r#"'{}': [{}],"#, id, resources_code); } dynamic_resources_code = format!("{{ {} }}", dynamic_resources_code); diff --git a/crates/plugin_lazy_compilation/src/dynamic_module.ts b/crates/plugin_lazy_compilation/src/dynamic_module.ts index da16f8c18..620043e50 100644 --- a/crates/plugin_lazy_compilation/src/dynamic_module.ts +++ b/crates/plugin_lazy_compilation/src/dynamic_module.ts @@ -6,8 +6,8 @@ interface LazyCompileResult { } const FarmModuleSystem: any = 'FARM_MODULE_SYSTEM'; -const moduleId = 'MODULE_ID'; -const modulePath = 'MODULE_PATH'; +const moduleId = `MODULE_ID`; +const modulePath = `MODULE_PATH`; FarmModuleSystem.lazyCompiling = false; FarmModuleSystem.compilingModules = new Map>(); diff --git a/crates/plugin_lazy_compilation/src/lib.rs b/crates/plugin_lazy_compilation/src/lib.rs index 2cb6134a4..0adf35de4 100644 --- a/crates/plugin_lazy_compilation/src/lib.rs +++ b/crates/plugin_lazy_compilation/src/lib.rs @@ -90,10 +90,12 @@ impl Plugin for FarmPluginLazyCompilation { if param.query.get("original").is_none() { let resolved_path = param.resolved_path; let dynamic_code = include_str!("dynamic_module.ts") - .replace("MODULE_PATH", resolved_path) + .replace("MODULE_PATH", &resolved_path.replace(r"\", r"\\")) .replace( "MODULE_ID", - &ModuleId::new(resolved_path, &context.config.root).id(context.config.mode.clone()), + &ModuleId::new(resolved_path, &context.config.root) + .id(context.config.mode.clone()) + .replace(r"\", r"\\"), ) .replace( "'FARM_MODULE_SYSTEM'", diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 76571c3e7..8f00aa08f 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,11 @@ # @farmfe/cli +## 0.3.1 + +### Patch Changes + +- Optimize disk usage + ## 0.3.0 ### Minor Changes diff --git a/packages/cli/package.json b/packages/cli/package.json index 9e0c2262b..5f8be0e7b 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@farmfe/cli", - "version": "0.3.0", + "version": "0.3.1", "description": "CLI of Farm", "type": "module", "author": { @@ -49,6 +49,6 @@ }, "devDependencies": { "@types/inquirer": "^9.0.3", - "@farmfe/core": "workspace:^0.3.0" + "@farmfe/core": "workspace:^0.3.3" } } diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts index 2880d11a2..0d0a3f09c 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -1,7 +1,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import path from 'node:path'; import Module from 'node:module'; -import { fileURLToPath } from 'node:url'; +import { fileURLToPath, pathToFileURL } from 'node:url'; import walkdir from 'walkdir'; import type { start, build } from '@farmfe/core'; @@ -39,5 +39,10 @@ export function resolveCore(cwd: string): Promise<{ }> { const require = Module.createRequire(path.join(cwd, 'package.json')); const farmCorePath = require.resolve('@farmfe/core'); + + if (process.platform === 'win32') { + return import(pathToFileURL(farmCorePath).toString()); + } + return import(farmCorePath); } diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 137ff8add..8d6adad9f 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,5 +1,11 @@ # @farmfe/core +## 0.3.3 + +### Patch Changes + +- Optimize disk usage + ## 0.3.2 ### Patch Changes diff --git a/packages/core/package.json b/packages/core/package.json index 4eb642eb7..7ff3e2634 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@farmfe/core", - "version": "0.3.2", + "version": "0.3.3", "main": "dist/index.js", "types": "dist/index.d.ts", "type": "module", diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.ts index 0fb6b060d..b0360a542 100644 --- a/packages/core/src/config/index.ts +++ b/packages/core/src/config/index.ts @@ -206,7 +206,7 @@ async function readConfigFile( if (resolvedPath.endsWith('.ts')) { const Compiler = (await import('../compiler/index.js')).Compiler; const outputPath = path.join(os.tmpdir(), 'farmfe'); - const fileName = 'farm.config.bundle.mjs'; + const fileName = `${Date.now()}-farm.config.bundle.mjs`; const normalizedConfig = await normalizeUserCompilationConfig({ compilation: { input: { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8f6dd625b..c2af9b508 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -71,7 +71,7 @@ importers: packages/cli: specifiers: - '@farmfe/core': workspace:^0.3.0 + '@farmfe/core': workspace:^0.3.3 '@types/inquirer': ^9.0.3 cac: ^6.7.14 chalk: ^5.2.0