Skip to content

Commit

Permalink
Fix/temp config add timestamp (#46)
Browse files Browse the repository at this point in the history
* chore: temp config file add time stamp

* chore: optimize disk usage
  • Loading branch information
wre232114 authored Mar 5, 2023
1 parent 2b01261 commit d2011e4
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 33 deletions.
26 changes: 11 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<br />


**Features**:

- 🔥 **Super Fast**: Start a react / vue(incoming) project in milliseconds.
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/compiler/src/generate/finalize_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn write_resources(context: &Arc<CompilationContext>) {
}

// Remove useless resources
// TODO support sub dir scene
let existing_resources = read_dir(output_dir.clone())
.unwrap()
.map(|entry| {
Expand Down
3 changes: 2 additions & 1 deletion crates/compiler/src/update/regenerate_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions crates/plugin_css/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 = `{}`;
Expand All @@ -75,7 +81,8 @@ if (previousStyle) {{
document.head.appendChild(style);
}}
"#,
param.content, param.resolved_path
param.content,
module_id.to_string()
);

Ok(Some(PluginTransformHookResult {
Expand Down
7 changes: 2 additions & 5 deletions crates/plugin_html/src/resources_injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions crates/plugin_lazy_compilation/src/dynamic_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Promise<any>>();
Expand Down
6 changes: 4 additions & 2 deletions crates/plugin_lazy_compilation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @farmfe/cli

## 0.3.1

### Patch Changes

- Optimize disk usage

## 0.3.0

### Minor Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@farmfe/cli",
"version": "0.3.0",
"version": "0.3.1",
"description": "CLI of Farm",
"type": "module",
"author": {
Expand Down Expand Up @@ -49,6 +49,6 @@
},
"devDependencies": {
"@types/inquirer": "^9.0.3",
"@farmfe/core": "workspace:^0.3.0"
"@farmfe/core": "workspace:^0.3.3"
}
}
7 changes: 6 additions & 1 deletion packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);
}
6 changes: 6 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @farmfe/core

## 0.3.3

### Patch Changes

- Optimize disk usage

## 0.3.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

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

0 comments on commit d2011e4

Please sign in to comment.