-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add hmr api and js plugin api
- Loading branch information
Showing
5 changed files
with
199 additions
and
84 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 |
---|---|---|
@@ -1 +1,65 @@ | ||
# Hmr Api | ||
:::note | ||
The HMR API is compatible with [Vite's HMR API](https://vitejs.dev/guide/api-hmr.html). | ||
::: | ||
|
||
Farm exposes its manual HMR API via the special import.meta.hot object(the same as Vite): | ||
```ts | ||
export interface ViteHotContext { | ||
readonly data: any; | ||
|
||
accept(): void; | ||
accept(cb: (mod: ModuleNamespace | undefined) => void): void; | ||
accept(dep: string, cb: (mod: ModuleNamespace | undefined) => void): void; | ||
accept( | ||
deps: readonly string[], | ||
cb: (mods: Array<ModuleNamespace | undefined>) => void | ||
): void; | ||
|
||
// acceptExports is not supported in Farm for now | ||
// acceptExports( | ||
// exportNames: string | readonly string[], | ||
// cb?: (mod: ModuleNamespace | undefined) => void | ||
// ): void; | ||
|
||
dispose(cb: (data: any) => void): void; | ||
prune(cb: (data: any) => void): void; | ||
invalidate(message?: string): void; | ||
|
||
on<T extends string>( | ||
event: T, | ||
cb: (payload: InferCustomEventPayload<T>) => void | ||
): void; | ||
off<T extends string>( | ||
event: T, | ||
cb: (payload: InferCustomEventPayload<T>) => void | ||
): void; | ||
send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void; | ||
} | ||
``` | ||
|
||
## Required Conditional Guard | ||
|
||
## IntelliSense for TypeScript | ||
|
||
## hot.accept() | ||
|
||
## hot.accept(cb) | ||
|
||
## hot.accept(deps, cb) | ||
|
||
## hot.dispose(cb) | ||
|
||
## hot.prune(cb) | ||
|
||
## hot.data | ||
|
||
## hot.decline() | ||
|
||
## hot.invalidate(message?: string) | ||
|
||
## hot.on(event, cb) | ||
|
||
## hot.off(event, cb) | ||
|
||
## hot.send(event, data) |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,32 @@ | ||
# Enviroment Variables and Modes | ||
# Enviroment Variables and Modes | ||
|
||
`Farm` distinguishes between development and production environments through `Farm` process.env.NODE\_ ENV`. | ||
|
||
In different environments, environment variables are replaced statically, so use static constants to represent environment variables instead of dynamic expressions. | ||
|
||
## `.env` file | ||
|
||
`Farm` uses `dotenv` to load your additional environment variables, such as `.env` files. | ||
|
||
```js | ||
// .env | ||
FARM_APP_SECRET=secret | ||
Farm_APP_PASSWORD=password | ||
APP_VERSION=1.0.0 | ||
``` | ||
|
||
`Farm` loads the file `.env` via dotenv, and loads it into `process.env` and finally injects it into define. | ||
|
||
:::warning | ||
In order to ensure the security of the client, preventing the environment variables in the current system from being exposed to the client `Farm` will only identify some important environment variables that start with `Farm`. | ||
::: | ||
|
||
`Farm` expands environment variables through dotenv-expand | ||
|
||
If you want to customize the prefix of env variables, you can configure `envPrefix`. | ||
|
||
## envPrefix | ||
|
||
- **default value**: `FARM_` | ||
|
||
Customize the prefix of the `env` variable by configuring `envPrefix`. |
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