-
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.
- Loading branch information
Showing
27 changed files
with
226 additions
and
122 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
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 |
---|---|---|
@@ -1,56 +1,52 @@ | ||
# HTML 模板 | ||
|
||
Fes.js 基于 [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) 实现的模板功能,默认模板内容是: | ||
Fes.js 默认模板内容是: | ||
|
||
```html | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<title><%= htmlWebpackPlugin.options.title %></title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0" /> | ||
<title><%= title %></title> | ||
</head> | ||
<body> | ||
<div id="<%= mountElementId %>"></div> | ||
</body> | ||
</html> | ||
``` | ||
|
||
## 自定义模板 | ||
在 `src/public` 文件夹中创建`index.html`,Fes.js 约定如果这个文件存在,则会替换默认模板。 | ||
|
||
## 模板配置 | ||
在配置文件(`.fes.js`)中配置 `html`,把[配置](https://github.com/jantimon/html-webpack-plugin#options)的对象作为参数传入 `html-webpack-plugin` 实例。 | ||
## 修改页面标题 | ||
|
||
举个 :chestnut: : | ||
```js | ||
// .fes.js | ||
export default { | ||
html: { | ||
title: '海贼王' | ||
} | ||
} | ||
title: '这是页面标题', | ||
}; | ||
``` | ||
页面的标题会设置成'海贼王'。 | ||
|
||
## 模板变量 | ||
当然我们也可以手动编写模板,在模板中添加`link`、`link`、`meta`等标签。在我们手动配置模板时,有时候需要用到一些环境变量,模板里可以获取到的变量如下: | ||
页面的标题会设置成 `这是页面标题`。 | ||
|
||
- **htmlWebpackPlugin**,特定于此插件的数据 | ||
- **webpackConfig**,用于此编译的webpack配置。例如,它可用于获取publicPath(webpackConfig.output.publicPath)。 | ||
- **compilation**,webpack编译对象。例如,可以使用它来获取已处理资产的内容,并将其直接内联到页面中compilation.assets[...].source() | ||
## 模板变量 | ||
|
||
举个 🌰 : | ||
```html | ||
<link rel="icon" type="image/x-icon" href="<%= webpackConfig.output.publicPath %>favicon.png" /> | ||
``` | ||
模版中可以使用的变量: | ||
|
||
除上述 `html-webpack-plugin` 插件提供的变量外,Fes.js 还把 `process.env` 中的环境变量添加到模板作用域内: | ||
- `NODE_ENV` | ||
- `FES_ENV` | ||
- `.env` 文件中以 `FES_APP_` 开头的变量 | ||
- `NODE_ENV`: Node.js 环境变量 | ||
- `FES_ENV`: Fes.js 环境变量 | ||
- `BASE_URL`: publicPath | ||
- `.env.**`: 文件中以 `FES_APP_` 开头的变量 | ||
|
||
举个 🌰 : | ||
|
||
```env | ||
# .env | ||
FES_APP_HELLO_WORLD=hello world | ||
``` | ||
|
||
```html | ||
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> | ||
``` | ||
<link rel="icon" href="<%= BASE_URL %>favicon.ico" /> | ||
<body> | ||
<div><%= FES_APP_HELLO_WORLD %></div> | ||
</body> | ||
``` |
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,22 @@ | ||
# 从 2.0.x 迁移到 2.1.x | ||
|
||
## 版本 2.1.x 的 break | ||
|
||
1. 编译时的 [base](../reference/config/#base) 配置,移到了 [router.base](../reference/config/#router) 下 | ||
|
||
## 相关插件 | ||
|
||
由于需要兼容 Vite 的写法,插件也做了相关代码调整, | ||
|
||
## 不变更构建方式 | ||
|
||
1. 添加 Webpack 构建依赖包: `npm i @fesjs/build-webpack -D`。 | ||
2. 如果有,将 `public/index.html` 文件挪到项目根目录,移除 [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) 相关配置,具体模版变量使用请查看[HTML 模版](../guide/template.html)。 | ||
|
||
## 换成 Vite | ||
|
||
1. 安装依赖包 `npm i @fesjs/build-vite`。 | ||
2. 将 Webpack 相关的配置换成 Vite,具体可查看[配置](../reference/config)。 | ||
3. 将 html 模版文件从 `public/index.html` 挪到项目根目录,如果有相应的 [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) 配置,需要改成 [vite-plugin-html](https://github.com/vbenjs/vite-plugin-html) 的写法。 | ||
4. 将 `require` 等 Vite 不支持的代码,改写成 Vite 支持的方式。 | ||
5. 由于需要兼容 Vite 写法,相关插件也做了相关调整,因此依赖的插件都需要升级最新的版本。如果用了 [@fesjs/plugin-sass](../reference/plugin/plugins/sass.html) 插件,直接移除,手动安装 `sass` 依赖即可。 |
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
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
10 changes: 10 additions & 0 deletions
10
packages/fes-preset-built-in/src/plugins/features/title.js
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,10 @@ | ||
export default (api) => { | ||
api.describe({ | ||
key: 'title', | ||
config: { | ||
schema(joi) { | ||
return joi.string(); | ||
}, | ||
}, | ||
}); | ||
}; |
Oops, something went wrong.