Bläddra i källkod

docs: update latest nextJs config demo

pointhalo 2 år sedan
förälder
incheckning
02506d19ad

+ 61 - 67
content/start/getting-started/index-en-US.md

@@ -7,7 +7,7 @@ localeCode: en-US
 order: 2
 ---
 
-## 1. Installation of Semi
+## 1. Install Library
 
 ```bash
 # with npm
@@ -19,15 +19,19 @@ yarn add @douyinfe/semi-ui
 # with pnpm
 pnpm add @douyinfe/semi-ui
 ```
-## 2、Use components in a modular way 💫
+## 2. Use components in a modular way 💫
+
+`Semi` provides esm format dist, and the css of the component is only imported by the corresponding js.  
+When used in `Webpack`, `create-react-app` or `Vite` projects, there is no need to configure any compilation items.   
+All related resources are packaged on-demand at build process. Tree shaking will work without additional configuration.
 
 ```jsx
 import React, { Component } from 'react';
 import { Button, Toast } from '@douyinfe/semi-ui';
 
 class Demo extends React.Component {
-    constructor() {
-        super();
+    constructor(props) {
+        super(props);
     }
 
     render() {
@@ -36,9 +40,47 @@ class Demo extends React.Component {
 }
 ```
 
-> It is recommended to introduce [reset.css](https://www.npmjs.com/package/reset-css) into the project, which can avoid introducing the default style of the browser.
+> It is recommended to import [reset.css](https://www.npmjs.com/package/reset-css) into the project, which can avoid introducing the default style of the browser.
+
+## 3、Use in Next.js
+- If you only use the default theme, you can add Semi-related packages to `transpilePackages` (Next.js version requires >= v13.1) . 
+```diff
+// next.config.js
+const nextConfig = {
++ transpilePackages: ['@douyinfe/semi-ui', '@douyinfe/semi-icons', '@douyinfe/semi-illustrations'],
+};
+
+module.exports = nextConfig;
+```
+
+- If you need to use a custom theme package or the version of Next.js is lower than v13.1, you need to use the compiling plugin `@douyinfe/semi-next` provided by Semi
+  - First install the plugin `npm i @douyinfe/semi-next` (if you use yarn or pnpm, please replace it with the equivalent command)
+  - Configured in `next.config.js`, the plugin will remove the default import CSS statement of the component. More configurations can be found `@douyinfe/semi-next`[Detail Config](https://www.npmjs.com/package/@douyinfe/semi-next) 
+  - import semi css in `global.css` (using this method in Next.js does not support on-demand import)
+```js
+// next.config.js
+const semi = require('@douyinfe/semi-next').default({
+    /* the extension options */
+});
+module.exports = semi({
+    // your custom Next.js configuration
+});
+```
+
+```css
+/* styles/globals.css */
+@import '~@douyinfe/semi-ui/dist/css/semi.min.css';
+```
+
+**How to use theme packages with Next.js**  
+You need to change the path of the import statement in globals.css, and replace the default theme CSS product with the CSS product in your customized theme package.  
+For example, when you want to use the theme package of the Douyin creation service platform `@semi-bot/semi-theme-doucreator` 
+```css
+/* styles/globals.css */
+@import '~@semi-bot/semi-theme-doucreator/semi.min.css';
+```
 
-## Use UMD import in browser
+## 4. Use UMD import in browser
 
 [![BUILD-JS][build-js-badge]][build-js-url] [![BUILD-CSS][build-css-badge]][build-css-url]
 
@@ -52,14 +94,14 @@ class Demo extends React.Component {
 Use script and link tags to import files directly in the browser, and use the global variable `SemiUI`、`SemiIcons`、`SemiIllustrations`
 
 1. Please make sure you have import `react` and `react-dom` in advance
-2. Import the JS file, the following example URL 2.1.4 is the version identifier, if you want to use a different version of Semi, just replace the corresponding value in version
+2. Import the JS file, the following example URL 2.27.0 is the version identifier, if you want to use a different version of Semi, just replace the corresponding value in version
 
 | Resource | URL |
 | --- | --- |
-| semi-ui (min) | https://unpkg.com/@douyinfe/semi-ui@2.1.4/dist/umd/semi-ui.min.js |
+| semi-ui (min) | https://unpkg.com/@douyinfe/semi-ui@2.27.0/dist/umd/semi-ui.min.js |
 | semi-icons (min) | https://unpkg.com/@douyinfe/semi-icons@latest/dist/umd/semi-icons.min.js |
 | semi-illustrations (min) | https://unpkg.com/@douyinfe/semi-illustrations@latest/dist/umd/semi-illustrations.min.js |
-| semi-ui (normal) | https://unpkg.com/@douyinfe/semi-ui@2.1.4/dist/umd/semi-ui.js |
+| semi-ui (normal) | https://unpkg.com/@douyinfe/semi-ui@2.27.0/dist/umd/semi-ui.js |
 | semi-icons (normal) | https://unpkg.com/@douyinfe/semi-icons@latest/dist/umd/semi-icons.js |
 | semi-illustrations (normal) | https://unpkg.com/@douyinfe/semi-illustrations@latest/dist/umd/semi-illustrations.js |
 
@@ -67,7 +109,7 @@ Use script and link tags to import files directly in the browser, and use the gl
 
 | Resource | URL |
 | --- | --- |
-| semi.css | https://unpkg.com/@douyinfe/semi-ui@2.1.4/dist/css/semi.css |
+| semi.css | https://unpkg.com/@douyinfe/semi-ui@2.27.0/dist/css/semi.css |
 | semi-icons.css | https://unpkg.com/@douyinfe/semi-icons@latest/dist/css/semi-icons.css |
 
 ```diff
@@ -78,8 +120,8 @@ Use script and link tags to import files directly in the browser, and use the gl
 +       <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
 +       <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
 
-+       <script src="https://unpkg.com/@douyinfe/semi-ui@2.1.4/dist/umd/semi-ui-react.min.js"></script>
-+       <link rel="stylesheet" href="https://unpkg.com/@douyinfe/semi-ui@2.1.4/dist/css/semi.css">
++       <script src="https://unpkg.com/@douyinfe/semi-ui@2.27.0/dist/umd/semi-ui-react.min.js"></script>
++       <link rel="stylesheet" href="https://unpkg.com/@douyinfe/semi-ui@2.27.0/dist/css/semi.css">
 
 +       <script src="https://unpkg.com/@douyinfe/semi-icons@latest/dist/umd/semi-icons.min.js"></script>
 +       <link rel="stylesheet" href="https://unpkg.com/@douyinfe/semi-icons@latest/dist/css/semi-icons.css">
@@ -98,61 +140,13 @@ Use script and link tags to import files directly in the browser, and use the gl
     const { IconHome } = SemiIcons;
     const { IllustrationConstruction } = SemiIllustrations;
     ReactDOM.render(
-    <div>
-        <Button onClick={() => Toast.warning({ duration: 0, content: 'Semi Design' })}>test</Button>
-        <Input defaultValue="semi" onChange={value => Toast.info('abc')}></Input>
-        <IconHome size="large" />
-        <IllustrationConstruction style={{width: 150, height: 150}} />
-    </div>, document.getElementById("root"));
+        <div>
+            <Button onClick={() => Toast.warning({ duration: 0, content: 'Semi Design' })}>test</Button>
+            <Input defaultValue="semi" onChange={value => Toast.info('hello')}></Input>
+            <IconHome size="large" />
+            <IllustrationConstruction style={{width: 150, height: 150}} />
+        </div>, document.getElementById("root")
+    );
 </script>
 ```
 
-## 4、Use in Next.js
-
-### Step1
-
-Install `@douyinfe/semi-next` in the project root directory.
-
-``` shell
-# with npm
-npm i @douyinfe/semi-next --save-dev
-
-# with yarn
-yarn add @douyinfe/semi-next --dev
-
-# with pnpm
-pnpm add @douyinfe/semi-next --dev
-
-```
-
-### Step2
-
-Create `next.config.js` in the project root directory and configure it.
-
-```js
-// next.config.js
-const semi = require('@douyinfe/semi-next').default({/* the extension options */});
-module.exports = semi({
-    // your custom Next.js configuration
-});
-```
-
-[Detailed documentation](https://www.npmjs.com/package/@douyinfe/semi-next) of `@douyinfe/semi-next`.
-
-### Step3
-
-Introduce the full amount of semi css in `global.css`. Currently, on-demand import is not supported.
-
-``` css
-/* styles/globals.css */
-@import '~@douyinfe/semi-ui/dist/css/semi.min.css';
-
-```
-
-**Using theme in nextjs**
-
-You need to replace the path of the import statement in Step3, and replace the default theme CSS product with the CSS product in your customized theme package, for example, the theme package is `@semi-bot/semi-theme-nyx-c`
-```css
-/* styles/globals.css */
-@import '~@semi-bot/semi-theme-nyx-c/semi.min.css';
-```

+ 21 - 34
content/start/getting-started/index.md

@@ -20,7 +20,7 @@ yarn add @douyinfe/semi-ui
 pnpm add @douyinfe/semi-ui
 ```
 
-## 2、模块化方式使用组件
+## 2、使用组件
 
 在 Webpack、create-react-app 或 Vite 项目中使用时,无需进行任何编译项配置,直接使用即可。构建时所有相关资源均会按需打包。
 
@@ -41,29 +41,22 @@ class Demo extends React.Component {
 
 > 推荐在项目中引入 [reset.css](https://www.npmjs.com/package/reset-css),它可以重置浏览器自带的默认样式,避免不同UA之间的样式差异。
 
-## 3、在 Next.js 中使用
+## 3、在 NextJs 中使用
 
-当你在 Next.js 项目中使用时,需要搭配 Semi 提供的编译插件(由于 Next.js 不允许 npm 包从 node_modules 中 import 样式文件,需要配合插件将默认的import CSS 语句移除,并且手动引入 CSS)
-
-### Step1
-
-在项目根目录安装 `@douyinfe/semi-next` 。
-
-```shell
-# 使用 npm
-npm i @douyinfe/semi-next
-
-# 使用 yarn
-yarn add @douyinfe/semi-next
+- 如果仅使用默认主题, 在 `transpilePackages` 追加 Semi 相关的 package即可 (Next.js 版本要求 >= v13.1 )
+```diff
+// next.config.js
+const nextConfig = {
++ transpilePackages: ['@douyinfe/semi-ui', '@douyinfe/semi-icons', '@douyinfe/semi-illustrations'],
+};
 
-# 使用 pnpm
-pnpm add @douyinfe/semi-next
+module.exports = nextConfig;
 ```
 
-### Step2
-
-在项目根目录创建 `next.config.js`,并进行配置。
-
+- 如果需要使用定制主题包或 Next.js版本低于 v13.1,则需要配合 Semi 提供的编译插件 `@douyinfe/semi-next` 插件使用 
+  - 首先安装插件 `npm i @douyinfe/semi-next` (如果你使用 yarn 或 pnpm,请自行更换为对等命令)
+  - 在 next.config.js 中进行配置,插件会将组件默认的import CSS 语句移除。更多配置可查阅 `@douyinfe/semi-next`[详细文档](https://www.npmjs.com/package/@douyinfe/semi-next) 
+  - 在 `global.css` 中引入全量的 semi css(目前在 Next.js 中不支持按需引入)
 ```js
 // next.config.js
 const semi = require('@douyinfe/semi-next').default({
@@ -74,22 +67,16 @@ module.exports = semi({
 });
 ```
 
-`@douyinfe/semi-next` 的 [详细文档](https://www.npmjs.com/package/@douyinfe/semi-next) 。
-
-### Step3
-
-在 `global.css` 中引入全量的 semi css。目前在 Next.js 中不支持按需引入。
-
 ```css
 /* styles/globals.css */
 @import '~@douyinfe/semi-ui/dist/css/semi.min.css';
 ```
 
 **如何在 Next.js 中使用主题包**  
-你需要更换 Step3 中 import 语句的路径,将默认主题 CSS 产物更换为你定制的主题包中的 CSS 产物,例如主题包为 `@semi-bot/semi-theme-nyx-c`
+你需要更换 globals.css 中 import 语句的路径,将默认主题 CSS 产物更换为你定制的主题包中的 CSS 产物,例如当希望应用抖音创作服务平台的主题包 `@semi-bot/semi-theme-doucreator` 时
 ```css
 /* styles/globals.css */
-@import '~@semi-bot/semi-theme-nyx-c/semi.min.css';
+@import '~@semi-bot/semi-theme-doucreator/semi.min.css';
 ```
 
 ## 4、UMD 方式使用组件
@@ -106,14 +93,14 @@ module.exports = semi({
 在浏览器中使用 script 和 link 标签直接引入文件,并使用全局变量 `SemiUI`、`SemiIcons`、`SemiIllustrations`
 
 1、 请确保你已提前引入 react 以及 react-dom  
-2、 引入 JS 文件,以下示例 URL 中 2.1.4 为 version 标识,希望使用不同版本 Semi 时,将 version 中对应的值替换即可  
+2、 引入 JS 文件,以下示例 URL 中 2.27.0 为 version 标识,希望使用不同版本 Semi 时,将 version 中对应的值替换即可  
 
 | 资源 | URL |
 | --- | --- |
-| semi-ui (min) | https://unpkg.com/@douyinfe/semi-ui@2.1.4/dist/umd/semi-ui.min.js |
+| semi-ui (min) | https://unpkg.com/@douyinfe/semi-ui@2.27.0/dist/umd/semi-ui.min.js |
 | semi-icons (min) | https://unpkg.com/@douyinfe/semi-icons@latest/dist/umd/semi-icons.min.js |
 | semi-illustrations (min) | https://unpkg.com/@douyinfe/semi-illustrations@latest/dist/umd/semi-illustrations.min.js |
-| semi-ui (normal) | https://unpkg.com/@douyinfe/semi-ui@2.1.4/dist/umd/semi-ui.js |
+| semi-ui (normal) | https://unpkg.com/@douyinfe/semi-ui@2.27.0/dist/umd/semi-ui.js |
 | semi-icons (normal) | https://unpkg.com/@douyinfe/semi-icons@latest/dist/umd/semi-icons.js |
 | semi-illustrations (normal) | https://unpkg.com/@douyinfe/semi-illustrations@latest/dist/umd/semi-illustrations.js |
 
@@ -121,7 +108,7 @@ module.exports = semi({
 
 | 资源 | URL |
 | --- | --- |
-| semi.css | https://unpkg.com/@douyinfe/semi-ui@2.1.4/dist/css/semi.css |
+| semi.css | https://unpkg.com/@douyinfe/semi-ui@2.27.0/dist/css/semi.css |
 | semi-icons.css | https://unpkg.com/@douyinfe/semi-icons@latest/dist/css/semi-icons.css |
 
 ```diff
@@ -132,8 +119,8 @@ module.exports = semi({
 +       <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
 +       <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
 
-+       <script src="https://unpkg.com/@douyinfe/semi-ui@2.1.4/dist/umd/semi-ui.min.js"></script>
-+       <link rel="stylesheet" href="https://unpkg.com/@douyinfe/semi-ui@2.1.4/dist/css/semi.css">
++       <script src="https://unpkg.com/@douyinfe/semi-ui@2.27.0/dist/umd/semi-ui.min.js"></script>
++       <link rel="stylesheet" href="https://unpkg.com/@douyinfe/semi-ui@2.27.0/dist/css/semi.css">
 
 +       <script src="https://unpkg.com/@douyinfe/semi-icons@latest/dist/umd/semi-icons.min.js"></script>
 +       <link rel="stylesheet" href="https://unpkg.com/@douyinfe/semi-icons@latest/dist/css/semi-icons.css">

+ 1 - 1
src/components/PageAnchor/index.jsx

@@ -17,7 +17,7 @@ const makeAnchorOfToken = data => {
 
 const PageAnchor = props => {
     const { data = [], slug } = props;
-    const skipCondition = ['accessibility', 'dark-mode', 'customize-theme', 'content-guidelines'].some(item => slug.includes(item));
+    const skipCondition = ['accessibility', 'dark-mode', 'customize-theme', 'content-guidelines', 'getting-started'].some(item => slug.includes(item));
 
     let flag = false;
     const makeAnchor = data => {