Browse Source

[init]
vue3 + vue-router + pinia + typescript + eslint + prettier + axios + element-pilus

szj 3 months ago
parent
commit
895b4e171a
19 changed files with 384 additions and 11 deletions
  1. 18 0
      .eslintrc.cjs
  2. 33 0
      .gitignore
  3. 9 0
      .prettierrc.json
  4. 30 11
      README.md
  5. 1 0
      env.d.ts
  6. 13 0
      index.html
  7. 40 0
      package.json
  8. 13 0
      postcss.config.js
  9. 1 0
      public/vite.svg
  10. 9 0
      src/App.vue
  11. 25 0
      src/assets/css/global.scss
  12. 1 0
      src/assets/css/index.scss
  13. 14 0
      src/main.ts
  14. 15 0
      src/router/index.ts
  15. 13 0
      src/view/HomeView.vue
  16. 47 0
      tsconfig.app.json
  17. 11 0
      tsconfig.json
  18. 31 0
      tsconfig.node.json
  19. 60 0
      vite.config.ts

+ 18 - 0
.eslintrc.cjs

@@ -0,0 +1,18 @@
+/* eslint-env node */
+require('@rushstack/eslint-patch/modern-module-resolution')
+
+module.exports = {
+  root: true,
+  'extends': [
+    // vue官方推荐 https://eslint.vuejs.org/rules/
+    'plugin:vue/vue3-essential',
+    'eslint:recommended',
+    '@vue/eslint-config-typescript',
+    '@vue/eslint-config-prettier/skip-formatting'
+  ],
+  parserOptions: {
+    ecmaVersion: 'latest'
+  }
+}
+
+// eslint9 迁移文档 https://eslint.vuejs.org/rules/

+ 33 - 0
.gitignore

@@ -0,0 +1,33 @@
+# Logs
+logs
+*.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+lerna-debug.log*
+
+node_modules
+.DS_Store
+dist
+dist-ssr
+coverage
+*.local
+
+# Editor directories and files
+.vscode/*
+!.vscode/extensions.json
+.idea
+.DS_Store
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?
+
+*.tsbuildinfo
+/.vscode
+/package-lock.json
+/components.d.ts
+/auto-imports.d.ts
+/dist.zip

+ 9 - 0
.prettierrc.json

@@ -0,0 +1,9 @@
+{
+  "$schema": "https://json.schemastore.org/prettierrc",
+  "semi": true,
+  "tabWidth": 2,
+  "singleQuote": true,
+  "printWidth": 200,
+  "trailingComma": "none",
+  "vueIndentScriptAndStyle": true
+}

+ 30 - 11
README.md

@@ -4,16 +4,35 @@
 
 
 
+## 技术栈
+
+- 构建工具:Vite
+- 格式规范:Prettier + Eslint(<9,日后视情况迁移) 
+- 语言框架:Vue3 + TypeScript
+- 状态管理:Pinia
+- UI框架:Element-Plus
+- 路由:Vue-Router
+- 网络请求库:Axios
+- CSS相关:Sass + PostCss + Normalize.css
+- 其他库:
+  - TS中Node.js核心模块类型库:@types/node
+  - 处理Node20的tsconfig:@tsconfig/node20
+  - 自动导入库:unplugin-auto-import
+  - Vue组件按需导入:unplugin-vue-components
+  - vue3自动引入icon:unplugin-icons
+
+
+
 ## git提交注释
 
-| 注释     | 说明               |
-| -------- | ------------------ |
-| fix      | 修复bug            |
-| feature  | 新功能、新添加     |
-| style    | 样式变更           |
-| lib      | 工具包 or 插件     |
-| refactor | 功能重构           |
-| revert   | 撤销上一次的commit |
-|          |                    |
-|          |                    |
-|          |                    |
+| 注释     | 说明                   |
+| -------- | ---------------------- |
+| feature  | 新功能、新添加         |
+| fix      | 修复bug                |
+| docs     | 文档修改               |
+| style    | 样式变更、风格变更     |
+| lib      | 工具包 or 插件         |
+| refactor | 功能重构               |
+| revert   | 撤销上一次的commit     |
+| test     | 测试用例、或者测试功能 |
+|          |                        |

+ 1 - 0
env.d.ts

@@ -0,0 +1 @@
+/// <reference types="vite/client" />

+ 13 - 0
index.html

@@ -0,0 +1,13 @@
+<!doctype html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <title>Vite + Vue + TS</title>
+  </head>
+  <body>
+    <div id="app"></div>
+    <script type="module" src="/src/main.ts"></script>
+  </body>
+</html>

+ 40 - 0
package.json

@@ -0,0 +1,40 @@
+{
+  "name": "freedomplan",
+  "private": true,
+  "version": "0.0.0",
+  "type": "module",
+  "scripts": {
+    "dev": "vite",
+    "build": "vue-tsc -b && vite build",
+    "preview": "vite preview"
+  },
+  "dependencies": {
+    "autoprefixer": "^10.4.19",
+    "axios": "^1.7.2",
+    "element-plus": "^2.7.7",
+    "normalize.css": "^8.0.1",
+    "pinia": "^2.1.7",
+    "postcss": "^8.4.39",
+    "sass": "^1.77.8",
+    "vue": "^3.4.29",
+    "vue-router": "^4.4.0"
+  },
+  "devDependencies": {
+    "@rushstack/eslint-patch": "^1.3.3",
+    "@tsconfig/node20": "^20.1.4",
+    "@types/node": "^20.14.10",
+    "@vitejs/plugin-vue": "^5.0.5",
+    "@vue/eslint-config-prettier": "^8.0.0",
+    "@vue/eslint-config-typescript": "^12.0.0",
+    "@vue/tsconfig": "^0.5.1",
+    "eslint": "^8.49.0",
+    "eslint-plugin-vue": "^9.17.0",
+    "prettier": "^3.3.3",
+    "typescript": "^5.2.2",
+    "unplugin-auto-import": "^0.18.0",
+    "unplugin-icons": "^0.19.0",
+    "unplugin-vue-components": "^0.27.3",
+    "vite": "^5.3.1",
+    "vue-tsc": "^2.0.21"
+  }
+}

+ 13 - 0
postcss.config.js

@@ -0,0 +1,13 @@
+import autoprefixer from 'autoprefixer';
+
+export default {
+  plugins: [
+    autoprefixer()
+  ]
+};
+
+// module.exports = {
+//   plugins: {
+//     autoprefixer: {}
+//   }
+// };

+ 1 - 0
public/vite.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

+ 9 - 0
src/App.vue

@@ -0,0 +1,9 @@
+<style scoped></style>
+
+<template>
+  <RouterView></RouterView>
+</template>
+
+<script setup lang="ts">
+import { RouterView } from "vue-router";
+</script>

+ 25 - 0
src/assets/css/global.scss

@@ -0,0 +1,25 @@
+// html,
+// body {
+//     width: 100%;
+//     height: 100%;
+//     font-family: 'AlibabaPuHuiTi';
+//     color: red;
+//     background-color: red;
+// }
+
+// html {
+//     font-size: 16px;
+// }
+
+// body {
+//     font-size: 14px;
+// }
+
+// header {
+//     background: #000;
+// }
+
+// :root {
+//     --el-input-text-color: red;
+//     --el-text-color-regular: red;
+// }

+ 1 - 0
src/assets/css/index.scss

@@ -0,0 +1 @@
+// 引入一个scss文件,global.scss才会全局生效

+ 14 - 0
src/main.ts

@@ -0,0 +1,14 @@
+import { createApp } from 'vue'
+import App from '@/App.vue'
+
+import 'normalize.css';
+import '@/assets/css/index.scss';
+
+import { createPinia } from 'pinia';
+import router from '@/router/index';
+
+
+const app = createApp(App);
+app.use(createPinia());
+app.use(router);
+app.mount('#app');

+ 15 - 0
src/router/index.ts

@@ -0,0 +1,15 @@
+import HomeView from "@/view/HomeView.vue";
+import { createRouter, createWebHistory } from "vue-router";
+
+const router = createRouter({
+    history: createWebHistory(import.meta.env.BASE_URL),
+    routes: [
+        {
+            path: '/',
+            name: 'home',
+            component: HomeView
+        }
+    ]
+});
+
+export default router;

+ 13 - 0
src/view/HomeView.vue

@@ -0,0 +1,13 @@
+<style lang="scss" scoped>
+  div {
+    display: flex;
+  }
+</style>
+
+<template>
+  <div>
+    <p>HelloWorld</p>
+  </div>
+</template>
+
+<script setup lang="ts"></script>

+ 47 - 0
tsconfig.app.json

@@ -0,0 +1,47 @@
+{
+  // 继承自 Vue 的默认 TypeScript 配置
+  "extends": "@vue/tsconfig/tsconfig.dom.json",
+  // 包含文件
+  "include": [
+    "env.d.ts",
+    "src/**/*",
+    "src/**/*.vue"
+  ],
+  // 忽略文件
+  "exclude": [
+    "src/**/__tests__/*"
+  ],
+  "compilerOptions": {
+    // 启用项目引用功能
+    "composite": true,
+    //指定 TypeScript 编译过程中的增量编译信息存储位置
+    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
+    // 设置解析非相对模块名称的基本目录
+    "baseUrl": ".",
+    // 设置模块导入路径的别名
+    "paths": {
+      "@/*": [
+        "./src/*"
+      ]
+    },
+    // 启用所有严格类型检查选项
+    "strict": false,
+    // 禁用严格的空值检查。
+    "strictNullChecks": false,
+    // 禁用隐式 any 类型检查
+    "noImplicitAny": false,
+
+    // 允许导入包含 .ts 扩展名的模块
+    "allowImportingTsExtensions": true,
+    // 确保每个文件都作为单独的模块进行编译
+    "isolatedModules": true,
+    // 强制所有文件都被视为模块
+    "moduleDetection": "force",
+    // 检查并报告未使用的局部变量
+    "noUnusedLocals": true,
+    // 检查并报告未使用的函数参数
+    "noUnusedParameters": true,
+    // 检查并报告 switch 语句中的非故意贯穿(fallthrough)情况
+    "noFallthroughCasesInSwitch": true
+  }
+}

+ 11 - 0
tsconfig.json

@@ -0,0 +1,11 @@
+{
+  "files": [],
+  "references": [
+    {
+      "path": "./tsconfig.app.json"
+    },
+    {
+      "path": "./tsconfig.node.json"
+    }
+  ]
+}

+ 31 - 0
tsconfig.node.json

@@ -0,0 +1,31 @@
+{
+  // 继承自 @tsconfig/node20 的默认配置
+  "extends": "@tsconfig/node20/tsconfig.json",
+  // 包含文件
+  "include": [
+    "vite.config.ts",
+    // "vitest.config.*",
+    // "cypress.config.*",
+    // "nightwatch.conf.*",
+    // "playwright.config.*"
+  ],
+  "compilerOptions": {
+    // 启用项目引用功能
+    "composite": true,
+    // 不生成任何输出文件
+    "noEmit": true,
+    // 指定 TypeScript 编译过程中的增量编译信息存储位置
+    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
+    
+    // 设置生成的 JavaScript 模块系统为 ESNext
+    "module": "ESNext",
+    // 指定模块解析策略为 Bundler
+    "moduleResolution": "bundler",
+    // 允许从没有默认导出的模块中进行默认导入
+    "allowSyntheticDefaultImports": true,
+    // 包含 Node.js 的类型定义
+    "types": [
+      "node"
+    ]
+  }
+}

+ 60 - 0
vite.config.ts

@@ -0,0 +1,60 @@
+import { defineConfig } from 'vite'
+import vue from '@vitejs/plugin-vue'
+
+import { fileURLToPath, URL } from 'node:url'
+import AutoImport from 'unplugin-auto-import/vite';
+import Components from 'unplugin-vue-components/vite';
+import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
+
+import IconsResolver from 'unplugin-icons/resolver';
+import Icons from 'unplugin-icons/vite';
+import autoprefixer from 'autoprefixer';
+
+// https://vitejs.dev/config/
+export default defineConfig({
+  plugins: [
+    vue(),
+    AutoImport({
+      imports: ['vue'],
+      resolvers: [
+        ElementPlusResolver({
+          importStyle: 'sass'
+        }),
+        IconsResolver({
+          prefix: 'Icon',
+        }),
+      ]
+    }),
+    Components({
+      resolvers: [
+        IconsResolver({
+          enabledCollections: ['ep'],
+        }),
+        ElementPlusResolver({
+          importStyle: 'sass'
+        }),
+      ]
+    }),
+    Icons({
+      autoInstall: true,
+    })
+  ],
+  resolve: {
+    alias: {
+      '@': fileURLToPath(new URL('./src', import.meta.url))
+    }
+  },
+  css: {
+    preprocessorOptions: {
+      scss: {
+        additionalData: `@import '@/assets/css/global.scss';`
+        // additionalData: `@use '@/assets/css/global.scss' as *;`
+      }
+    },
+    postcss: {
+      plugins: [
+        autoprefixer
+      ]
+    }
+  }
+})