| 静态网站开发框架 | 健壮静态网站搭建 | WEB环境小结 | PowerShell 环境支持 | 浏览器发展 | 浏览器 | AutoCAD下python部署 | pyautocad部署 | Win11系统配置 | Python安装及环境配置 | 常用软件参考链接 | kimi官网 | DeepSeek |
X:\erbcc
├── node_modules/ # 项目依赖
├── public/ # 静态资源目录
├── src/ # 源代码目录
│ ├── assets/ # 图片、字体等资源
│ ├── components/ # Vue 组件
│ ├── pages/ # 页面组件
│ ├── styles/ # 样式文件
│ │ └── main.css # 主样式文件
│ ├── App.vue # Vue 根组件
│ ├── main.js # 应用入口文件
│ └── index.html # 主页面
├── .gitignore # Git 忽略配置
├── package.json # 项目配置和依赖
├── vite.config.js # Vite 配置文件
└── postcss.config.js # PostCSS 配置文件
npm run dev
| 命令 | 功能 | 说明 |
|---|---|---|
| npm run dev | 启动开发服务器 | 开发时使用 |
| npm run build | 构建生产版本 | 输出到 dist/ 目录 |
| npm run preview | 预览生产构建 | 本地测试生产版本 |
| npm run lint | 代码检查 | 使用 ESLint |
| npm run format | 代码格式化 | 使用 Prettier |
# 添加生产依赖
npm install <package-name> --save# 添加开发依赖
npm install <package-name> --save-dev
vue复制代码<template>
<div class="my-component">
<!-- 组件内容 -->
</div>
</template><script>
export default {
name: 'MyComponent',
// 组件逻辑
}
</script><style scoped>
/* 组件样式 */
</style>
javascript复制代码import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'export default defineConfig({
root: 'src', // 项目根目录
publicDir: 'public', // 静态资源目录
plugins: [vue()], // Vue 插件
build: {
outDir: '../dist', // 构建输出目录
emptyOutDir: true, // 构建前清空目录
assetsInlineLimit: 0 // 资源内联限制
},
server: {
port: 3000, // 开发服务器端口
open: true, // 启动时自动打开浏览器
cors: true // 启用 CORS
},
css: {
postcss: './postcss.config.js' // PostCSS 配置
}
})
module.exports = {javascript复制代码
plugins: [
require('autoprefixer'), // 自动添加浏览器前缀
// 可添加更多 PostCSS 插件
]
}
组件设计:
状态管理:
性能优化:
浏览器开发者工具:
Vite 控制台命令:
npm run build
传统部署:
location / { try_files $uri $uri/ /index.html; }
Docker 容器化部署:
# Dockerfile
FROM node:20-alpine as builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run buildFROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
云平台部署:
# 清除缓存并重装
npm cache clean --force
rm -rf node_modules package-lock.json
npm install --registry=https://registry.npmmirror.com
修改 vite.config.js:
javascript复制代码server: {
port: 3001 // 更换端口
}
npm install typescript @vitejs/plugin-vue-jsx --save-dev
json复制代码{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"strict": true,
"jsx": "preserve",
"moduleResolution": "node",
"esModuleInterop": true,
"sourceMap": true,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}
bash复制代码npm install vue-router@4
创建 src/router/index.js:
javascript复制代码import { createRouter, createWebHistory } from 'vue-router'
const routes = [
{ path: '/', component: () => import('@/pages/Home.vue') },
{ path: '/about', component: () => import('@/pages/About.vue') }
]export default createRouter({
history: createWebHistory(),
routes
})
bash复制代码# 检查过时包 npm outdated # 更新依赖 npm update # 更新 npm 本身 npm install -g npm@latest
提交前检查:
bash复制代码npm run lint npm run format
Git 钩子 (使用 husky):
bash复制代码npx husky-init && npm install
单元测试 (使用 Vitest):
bash复制代码npm install vitest @vue/test-utils --save-dev
此开发环境为您提供了现代化的前端开发体验,结合了 Vite 的极速构建能力和 Vue 的响应式框架。祝您在 ERBCC 项目开发中取得成功!