项目初始化

创建项目

pnpm create vite

安装依赖

pnpm i @vueuse/core axios lodash pinia vue-router 
pnpm i -D @antfu/eslint-config autoprefixer eslint postcss prettier sass-embedded tailwindcss unplugin-auto-import unplugin-vue-components unplugin-vue-router vite-plugin-svg-icons vite-plugin-vue-devtools vite-plugin-vue-layouts

重置css

/* http://meyerweb.com/eric/tools/css/reset/ 
  v2.0 | 20110126
  License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}

基础vite配置

import path from 'node:path'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { VueRouterAutoImports } from 'unplugin-vue-router'
import VueRouter from 'unplugin-vue-router/vite'
import { defineConfig } from 'vite'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import vueDevTools from 'vite-plugin-vue-devtools'
import Layouts from 'vite-plugin-vue-layouts';

// https://vitejs.dev/config/
export default defineConfig({
 server: {
   host: '0.0.0.0',
   port: 3770,
},
 resolve: {
   alias: [{
     find: '@',
     replacement: '/src',
  }],
},
 plugins: [
   VueRouter(),
   vue(),
   Layouts(),
   Components({ /* options */ }),
   AutoImport({
     // targets to transform
     include: [
       /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
       /\.vue$/,
       /\.vue\?vue/, // .vue
       /\.md$/, // .md
    ],

     // global imports to register
     imports: [
       // presets
       'vue',
       VueRouterAutoImports,
       // custom
      {
         '@vueuse/core': ['useWindowSize', 'createGlobalState'],
         'axios': [['default', 'axios']],
         'pinia': ['storeToRefs'],
         'lodash': ['cloneDeep'],
      },
    ],

     // Enable auto import by filename for default module exports under directories
     defaultExportByFilename: false,

     // Auto import for module exports under directories
     // by default it only scan one level of modules under the directory
     dirs: [
       'src/utils/*',
       'src/module/*',
       'src/hooks/*',
       'src/store/*',
    ],

     // Filepath to generate corresponding .d.ts file.
     // Defaults to './auto-imports.d.ts' when `typescript` is installed locally.
     // Set `false` to disable.
     dts: './auto-imports.d.ts',

     // Array of strings of regexes that contains imports meant to be ignored during
     // the declaration file generation. You may find this useful when you need to provide
     // a custom signature for a function.
     ignoreDts: [
       'ignoredFunction',
       /^ignore_/,
    ],

     // Auto import inside Vue template
     // see https://github.com/unjs/unimport/pull/15 and https://github.com/unjs/unimport/pull/72
     vueTemplate: false,

     // Custom resolvers, compatible with `unplugin-vue-components`
     // see https://github.com/antfu/unplugin-auto-import/pull/23/
     resolvers: [
       /* ... */
    ],

     // Include auto-imported packages in Vite's `optimizeDeps` options
     // Recommend to enable
     viteOptimizeDeps: true,

     // Inject the imports at the end of other imports
     injectAtEnd: true,
  }),
   vueDevTools(),
   createSvgIconsPlugin({
     // Specify the icon folder to be cached
     iconDirs: [path.resolve(process.cwd(), 'src/icons')],
     // Specify symbolId format
     symbolId: 'icon-[dir]-[name]',

     /**
      * custom insert position
      * @default: body-last
      */
     inject: 'body-last',

     /**
      * custom dom id
      * @default: __svg__icons__dom__
      */
     customDomId: '__svg__icons__dom__',
  }),
],
})

tsconfig.app.json

{
 "compilerOptions": {
   "target": "ES2020",
   "jsx": "preserve",
   "lib": ["ES2020", "DOM", "DOM.Iterable"],
   "moduleDetection": "force",
   "useDefineForClassFields": true,
   "baseUrl": ".",
   "module": "ESNext",
   /* Bundler mode */
   "moduleResolution": "bundler", // 通常是项目的根目录
   "paths": {
     "@/*": ["src/*"]
  },
   "types": ["vite-plugin-vue-layouts/client"],
   "allowImportingTsExtensions": true,
   /* Linting */
   "strict": true,
   "noFallthroughCasesInSwitch": true,
   "noUnusedLocals": true,
   "noUnusedParameters": true,
   "noEmit": true,
   "isolatedModules": true,
   "skipLibCheck": true
},
 "include": [
   "src/**/*.ts",
   "src/**/*.tsx",
   "src/**/*.vue",
   "src/**/*.d.ts",
   "auto-imports.d.ts",
   "components.d.ts",
   "typed-router.d.ts"
]
}

tsconfig.node.json

{
 "compilerOptions": {
   "target": "ES2022",
   "lib": ["ES2023"],
   "moduleDetection": "force",
   "module": "ESNext",

   /* Bundler mode */
   "moduleResolution": "bundler",
   "allowImportingTsExtensions": true,

   /* Linting */
   "strict": true,
   "noFallthroughCasesInSwitch": true,
   "noUnusedLocals": true,
   "noUnusedParameters": true,
   "noEmit": true,
   "isolatedModules": true,
   "skipLibCheck": true
},
 "include": ["vite.config.ts"]
}
 
posted @   犬の技術  阅读(2)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示