vitepress version and other information
{
"devDependencies": {
"less": "^4.2.0",
"markdown-it": "^13.0.2",
"markdown-it-container": "^3.0.0",
"markdown-it-mathjax3": "^4.3.2",
"postcss": "^8.4.31",
"vite-plugin-svg-icons": "^2.0.1",
"vitepress": "^1.0.0-rc.24",
"vitepress-plugin-sandpack": "^1.1.4"
},
"dependencies": {
"element-plus": "^2.4.2",
"markdown-it-custom-attrs": "^1.0.2",
"unocss": "^0.57.7",
"viewerjs": "^1.11.6"
},
"engines": {
"node": ">19"
}
}
** script file
Create 3 core files
- Dockerfile
- .dockerignore
- nginx.conf
** Dockerfile
**
FROM node:20.9.0
WORKDIR /app
COPY package.json ./
RUN npm install -g pnpm && pnpm install
COPY . .
RUN pnpm run docs:build
FROM nginx:latest
COPY --from=0 /app/dist /usr/share/nginx/html
COPY --from=0 /app/nginx.conf /etc/nginx/conf.d/default.conf
The dist directory of my docker command copy here is in the root directory, that is, when npm run docs:build is executed, the dist folder is in the project The root directory is generated in .vitepress/dist by default. You need to adjust the configuration file of vitepress.
*.vitepress/config.js
*
import { defineConfig } from 'vitepress'
import { fileURLToPath } from 'node:url'
export default defineConfig({
srcExclude: ["./source-doc/**", 'README.md', 'Dockerfile', 'nginx.conf', '.dockerignore'],
outDir: fileURLToPath(new URL('../dist', import.meta.url)),
})
The following content does not need to be copied into docker, so ignore it. The above copy uses copy . . to copy all the files in the current directory into the set working directory /app. If ignored here, these contents will be skipped.
**.dockerignore
node_modules
.git
scripts
source-doc
README.md
dist
** nginx configuration
**nginx.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
location = 50x.html {
root /usr/share/nginx/html;
}
}
* Build image
* Use docker to build the image directly
docker build -t vitepress-doc .
* start up *
docker run -itd -p 8001:80 --name vitepress-doc vitepress-doc
Open browser address
http://localhost:8001
Top comments (0)