Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(update): 文档示例代码里文件路径的注释提取到代码块的 title 里 #8133

Merged
merged 8 commits into from
Nov 26, 2020
6 changes: 3 additions & 3 deletions docs/config-detail.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ title: 编译配置详情

配置方式可参考 [Webpack DefinePlugin](https://webpack.js.org/plugins/define-plugin/),例如:

```js
```js title="/config/index.js"
module.exports = {
// ...
defineConstants: {
Expand Down Expand Up @@ -110,7 +110,7 @@ import projectConfig from '@/project'

**config/dev.js**:

```jsx
```jsx title="/config/dev.js"
module.exports = {
// ...
env: {
Expand All @@ -121,7 +121,7 @@ module.exports = {

**config/prod.js**:

```jsx
```jsx title="config/prod.js"
module.exports = {
// ...
env: {
Expand Down
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ title: 编译配置

## index.js —— 通用配置

```js
```js title="/config/index.js"
const config = {
// 项目名称
projectName: 'Awesome Next',
Expand Down
6 changes: 3 additions & 3 deletions docs/css-in-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm i linaria

其次配置项目根目录的 `babel.config.js`:

```js
```js title="babel.config.js"
module.exports = {
presets: [
['taro', {
Expand All @@ -30,7 +30,7 @@ module.exports = {

之后配置 `config/index.js`

```js
```js title="config/index.js"
const config = {
mini: {
webpackChain(chain, webpack) {
Expand All @@ -49,7 +49,7 @@ const config = {

最后在项目根目录新建 `linaria.config.js`

```js
```js title="linaria.config.js"
// linaria 配置详见 https://github.com/callstack/linaria/blob/master/docs/CONFIGURATION.md#options
module.exports = {
rules: [
Expand Down
4 changes: 2 additions & 2 deletions docs/css-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Taro 中内置了 [CSS Modules](https://github.com/css-modules/css-modules) 的

小程序端开启

```js
```js title="config/index.js"
weapp: {
module: {
postcss: {
Expand All @@ -27,7 +27,7 @@ weapp: {

H5 端开启

```js
```js title="config/index.js"
h5: {
module: {
postcss: {
Expand Down
6 changes: 3 additions & 3 deletions docs/debug-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ yarn global add rollup

launch.json 有以下预设配置:

```json
```json title="launch.json"
{
// ...
"configurations": [
Expand Down Expand Up @@ -83,7 +83,7 @@ launch.json 有以下预设配置:

可以这样配置 launch.json:

```json
```json title="launch.json"
{
// ...
"configurations": [
Expand All @@ -108,7 +108,7 @@ launch.json 有以下预设配置:

可以这样配置 launch.json:

```json
```json title="launch.json"
{
// ...
"configurations": [
Expand Down
3 changes: 2 additions & 1 deletion docs/envs-debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ title: 多端同步调试
---

从 1.3.5 版本开始,可以在 dist 目录下创建一个与编译的目标平台名同名的目录,并将结果放在这个目录下,例如编译到微信小程序,最终结果是在 dist/weapp 目录下,这样做的好处是,各个平台使用独立的目录互不影响,从而达到多端同步调试的目的,在 `config/index.js` 配置如下:
```

```js title="/config/index.js"
outputRoot: `dist/${process.env.TARO_ENV}`
```

Expand Down
6 changes: 3 additions & 3 deletions docs/envs.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ import Test from '../../components/test'

增加 `set_title.h5.js`,代码如下

```js
```js title="set_title.h5.js"
export default function setTitle (title) {
document.title = title
}
```

增加 `set_title.weapp.js`,代码如下

```js
```js title="set_title.weapp.js"
import Taro from '@tarojs/taro'
export default function setTitle (title) {
Taro.setNavigationBarTitle({
Expand Down Expand Up @@ -145,7 +145,7 @@ Taro 3 里的多端文件由 [MultiPlatformPlugin](https://github.com/NervJS/tar

假如我们有一个 npm 包名叫 @taro-mobile,需要解析里面的多端文件,可以在 taro 的配置文件中这样修改 MultiPlatformPlugin 的配置:

```js
```js title="/config/index.js"
// mini 也可改为 h5,分别对应小程序与 h5 端配置
mini: {
webpackChain (chain) {
Expand Down
9 changes: 3 additions & 6 deletions docs/mini-third-party.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Taro 支持使用小程序的第三方组件和插件,使用方式也异常的

> 注意:Taro3 中没有自定义组件,组件是没有配置文件的。usingComponents 必须配置在“页面”的配置文件中。

```js
// page.config.js
```js {2} title="page.config.js"
export default {
usingComponents: {
// 定义需要引入的第三方组件
Expand All @@ -32,8 +31,7 @@ export default {

2. JSX 中引用

```jsx
// page.js
```jsx {14} title="page.js"
import React, { Component } from 'react'
import { View } from '@tarojs/components'

Expand Down Expand Up @@ -83,8 +81,7 @@ page.selectComponent('#mychart-dom-area')

使用插件前,使用者要在 `app.confg.js` 的配置中声明需要使用的插件,例如

```jsx
// app.config.js
```jsx title="app.config.js"
export default {
plugins: {
myPlugin: {
Expand Down
10 changes: 5 additions & 5 deletions docs/miniprogram-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ taro build --plugin weapp --watch

plugin.json 的 **pages** 字段加入页面插件路径:

```json
```json title="plugin.json"
{
"pages": {
"list": "pages/list/list"
Expand All @@ -60,7 +60,7 @@ plugin.json 的 **pages** 字段加入页面插件路径:

页面使用路径: **plugin://[app.js 中注册的插件名]/[plugin.json 中注册的页面名]** 进行跳转。

```jsx
```jsx {1}
<Navigator url='plugin://myPlugin/list'>
Go to pages/list!
</Navigator>
Expand All @@ -70,7 +70,7 @@ plugin.json 的 **pages** 字段加入页面插件路径:

plugin.json 的 **publicComponents** 字段加入组件插件路径:

```json
```json title="plugin.json"
{
"publicComponents": {
"avatar": "components/avatar/avatar"
Expand All @@ -80,7 +80,7 @@ plugin.json 的 **publicComponents** 字段加入组件插件路径:

在页面配置 config.usingComponents 中配置好插件名和插件路径(**plugin://[app.js 中注册的插件名]/[plugin.json 中注册的组件名]**):

```jsx
```jsx {4}
export default class Index extends Component {
config = {
usingComponents: {
Expand Down Expand Up @@ -114,7 +114,7 @@ const extraProps = {

plugin.json 的 **main** 字段加入接口插件路径:

```json
```json title="plugin.json"
{
"main": "index.js"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/nerv.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ title: Nerv

在使用第三方 React 库时,需要在[配置文件](config-detail.md#miniwebpackchain) `webpack.resolve.alias`,把 `react` 和 `react-dom` 映射到 `nervjs`:

```js
```js title="/config/index.js"
{
webpackChain (chain, webpack) {
chain.merge({
Expand Down
15 changes: 5 additions & 10 deletions docs/platform-plugin-base.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ title: TaroPlatformBase

例如我们创建一个微信小程序平台:

```js
// program.ts
```js title="program.ts"
import { TaroPlatformBase } from '@tarojs/service'
export default class Weapp extends TaroPlatformBase {
// ...
Expand Down Expand Up @@ -184,8 +183,7 @@ runner(options)

### 1. 继承基类

```js
// program.ts
```js title="program.ts"
import { TaroPlatformBase } from '@tarojs/service'

class Weapp extends TaroPlatformBase {
Expand Down Expand Up @@ -234,8 +232,7 @@ class Weapp extends TaroPlatformBase {

规范:

```js
//components.ts
```js title="components.ts"
import { singleQuote } from '@tarojs/shared'

export const components = {
Expand Down Expand Up @@ -319,8 +316,7 @@ internalComponent = {

除了借助 `template.mergeComponents` 进行合并,我们也可以直接修改 `template.internalComponents`。

```js
// program.ts
```js title="program.ts"
class Weapp extends TaroPlatformBase {
modifyComponents () {
// 删除 Slider 组件里的一些属性
Expand Down Expand Up @@ -376,8 +372,7 @@ class Weapp extends TaroPlatformBase {

我们创建的平台类需要编写一个对外的接口,在其中对编译流程进行设计,最终目标是调用 `@tarojs/mini-runner` 驱动 **Webpack** 开启编译。

```js
// program.ts
```js title="program.ts"
class Weapp extends TaroPlatformBase {
// ...
async start () {
Expand Down
18 changes: 6 additions & 12 deletions docs/platform-plugin-how.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ title: 编写端平台插件

首先我们需要编写一个 Taro 插件来注册我们的编译平台,如:

```js
// index.ts
```js title="index.ts"
export default (ctx) => {
ctx.registerPlatform({
name: 'weapp',
Expand Down Expand Up @@ -99,8 +98,7 @@ Taro 小程序相关配置默认放在 `mini` 字段下,因此一般情况配

然后在插件入口函数中调用上述自定义平台类的编译接口:

```js
// index.ts
```js title="index.ts"
import Weapp from './program'

export default (ctx) => {
Expand Down Expand Up @@ -221,8 +219,7 @@ export function initNativeApi (taro) {

当前扩展的小程序平台如果需要额外新增 API,建议使用一个 `apis-list.ts` 文件维护:

```js
// apis-list.ts
```js title="apis-list.ts"
// 微信小程序部分扩展 API
export const _onAndSyncApis = new Set([
'getAccountInfoSync'
Expand Down Expand Up @@ -279,8 +276,7 @@ function processApis (taro) {

注意,Taro 相关的包需要配置 `external`,以免重复打包:

```js
// rollup.config.js
```js title="rollup.config.js"
{
external: ['@tarojs/shared', '@tarojs/service']
}
Expand All @@ -292,8 +288,7 @@ Taro 核心库维护的类型可能没有包括当前插件新增的组件和 AP

创建一个类型定义文件:

```ts
// types/shims-iot.d.ts
```ts title="types/shims-iot.d.ts"
// 为支付宝 IOT 小程序拓展新增的 API 和组件定义
import { ComponentType } from 'react'
import Taro from '@tarojs/taro'
Expand All @@ -319,7 +314,6 @@ declare module '@tarojs/components' {

开发者在类型定义文件中引入此文件即可:

```ts
// global.d.ts
```ts title="global.d.ts"
/// <reference path="node_modules/@tarojs/plugin-platform-alipay-iot/types/shims-iot.d.ts" />
```
4 changes: 2 additions & 2 deletions docs/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Taro 提供了一些官方插件

`plugins` 字段取值为一个数组,配置方式如下:

```js
```js title="/config/index.js"
const config = {
plugins: [
// 引入 npm 安装的插件
Expand All @@ -46,7 +46,7 @@ const config = {

配置[编译配置](./config-detail.md)中的 `presets` 字段,如下。

```js
```js title="/config/index.js"
const config = {
presets: [
// 引入 npm 安装的插件集
Expand Down
3 changes: 1 addition & 2 deletions docs/prerender.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Taro Next 在一个页面加载时需要经历以下步骤:

使用 Prerender 非常简单,你可以找到项目根目录下的 `config` 文件夹,根据你的项目情况更改 `index.js`/`dev.js`/`prod.js` 三者中的任意一个[项目配置](./config.md),在编译时 Taro CLI 会根据你的配置自动启动 prerender:

```js
// /project/config/prod.js
```js title="/config/index.js 或 /config/dev.js 或 /config/prod.js "
const config = {
...
mini: {
Expand Down
Loading