Home > Web Front-end > Vue.js > What is vitepress? How to upgrade vuepress to vitepress?

What is vitepress? How to upgrade vuepress to vitepress?

青灯夜游
Release: 2021-11-15 18:54:34
forward
5305 people have browsed it

What is vitepress? This article will take you through the advantages of vitepress and introduce how to upgrade vuepress to vitepress. I hope it will be helpful to you!

What is vitepress? How to upgrade vuepress to vitepress?

Before vue3, I believe everyone has used or heard of vuepress. It is a static website generator based on vue that can be used to write documents. For specific content, please see VuePress official website.
But now there is vue3, there is also vite, and then there is a vitepress built on top of vite. (For the motivation generated by Vitepress, you can check the official website for explanation). [Related recommendations: "vue.js Tutorial"]

Advantages of vitepress

  • Based on vite instead of webpack, all faster startup times, hot reloading Load etc
  • Use vue3 to reduce the payload of js

.vitepress/config.js

vitepress improvements

Used vue3

  • Used vue3's improved template static analysis to stringify static content as much as possible

  • Used vite

    • Faster dev service startup

    • Faster hot updates

    • Faster builds ( Using Rollup)

A more lightweight page

  • vue 3 Tree Shake Rollup Code Separation
  • The metadata of all pages will not be sent in one request. When the client navigates, the components and metadata of the new page are obtained together
  • Not used vue-router
  • (WIP) i18n localization data is requested as needed

Differences

  • vitepress less configuration. The goal of vitepress is to reduce the complexity of the current vuepress and start again from the roots of minimalism
  • is future-oriented: its target browsers are browsers that only support the import of native ES modules. Encourage the use of native js instead of escaping and the use of css variables to subject

Upgrade process

The vitepress used below is version v0.20.0

1. Install vitepress

npm install vitepress
Copy after login

It turns out that when using vuepress, there will definitely be a docs folder (if not, you can create it yourself one).

2. Change the entry file to index.md

Note: The entry file of vuepress is docs/readme.md, and the entry file of vitepress is index.md, so this place To change the name of the original readmeIf index.md has no other content, you can add some simple content

---
home: true
title: 主页
lang: en-US
heroText: BIFE文档库
tagline: 这是你的舞台,期待你的精彩
actionText: Get Started
actionLink: /新人须知/first-day
footer: MIT Licensed | Copyright © 2021-present CoolDream
---
Copy after login

3. Configure vitepress information

  • Create .vitepress Folder
  • Create the configuration file under .vitepressconfig.js
  • In config.js Add configuration information
export default {
    base: '', // 项目的基础路径
    title: '文档', // 文档的标题,会显示在
    description: '前端技术文档', // 文档描述
    lastUpdated: '上次更新时间', // string | boolean
}
Copy after login

4. If you want to add the right navigation at the top, you can add <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:js;toolbar:false;">module.exports = { themeConfig: { // 顶部右侧导航 nav: [ { text: &amp;#39;Home&amp;#39;, link: &amp;#39;/first-day&amp;#39; }, { text: &amp;#39;Components&amp;#39;, link: &amp;#39;/test&amp;#39; }, ], } }</pre><div class="contentsignin">Copy after login</div></div>

in

themeConfig Note: nav The navigation link needs to be consistent with the linked file name and is case-sensitive

5. Add the left navigation and also add

in

themeConfig It should be noted that the link children in

vuepress is a specific link, and the displayed navigation name is the title in each .md file

The children of vitepress is an object array, text represents the navigation name, and link is the real link

If there are multiple routes, be sure to write the default route at the end

module.exports = {
    themeConfig: {
        // 侧边栏
        sidebar: [
            &#39;/CHANGLOG&#39;:[
                {
                    text: &#39;更新日志&#39;
                }
            ],
            &#39;/&#39;: [
                {
                    text: &#39;新人须知&#39;,
                    children: [
                        {
                          text: &#39;入职第一天&#39;,
                          link: &#39;/first-day&#39;
                        },
                        {
                            text: &#39;入职第一周&#39;,
                            link: &#39;/first-week&#39;
                        }
                     ]
                 }
             ]
        ],
        
    }
}
Copy after login

6. Add the script to package.json

"scripts": {
    "dev": "vitepress dev docs",
    "build": "vitepress build docs",
    "notice": "sh scripts/notice.sh"
 },
Copy after login

7. Uninstall vuepress

npm uninstall vuepress
Copy after login

Problems encountered during the upgrade

Does not take effect when switching multiple routes

At first, I wrote the default route at the front. I found that the route was not updated when I switched routes, and it was still the default route. Later I found that I needed to put the default route. Written in the last

themeConfig:{
    // 侧边栏
    sidebar: {
        // 其他路由在前
        &#39;other-router&#39;:[],
        // 默认路由在最后
        &#39;/&#39;: [
            {
                text: &#39;新人须知&#39;,
                children: [
                    {
                      text: &#39;入职第一天&#39;,
                      children: [
                          {text: &#39;电脑&#39;}
                      ]
                    }
                ]
            }
        ]
     }
}
Copy after login

table format in markdown (an error will be reported during build)

There cannot be a space after the data type. The number of rows reported in the error does not match at all, which leads to troubleshooting. (for a long time), as shown below

What is vitepress? How to upgrade vuepress to vitepress?

The internal link path of the file must be .md or omitted, and cannot be other file types (an error will be reported when building)

vitepress will convert the last level of the path to *.html (if it ends with /, go back and find index.md in the folder) , if it is other file types, if *.txt, the file

will not be found.

Links inside markdown cannot contain Chinese (an error will be reported when building)

If there is such a link format in markdown[Technology Sharing](/Technology Sharing/WebComponents/), an error will be reported when npm run build. The error message is as shown below. In this case, use <a href=""></a> tag link instead

What is vitepress? How to upgrade vuepress to vitepress?

The link in markdown requires http protocol (an error will be reported when building)

If there is no http protocol, an error will also be reported

More programming related knowledge, Please visit: Introduction to Programming! !

The above is the detailed content of What is vitepress? How to upgrade vuepress to vitepress?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template