From d75ae5fc3e91d69fb7ca1614564ef0851a545db4 Mon Sep 17 00:00:00 2001
From: pany <939630029@qq.com>
Date: Thu, 21 Apr 2022 14:14:40 +0800
Subject: [PATCH] =?UTF-8?q?chore:=20=E5=9F=BA=E7=A1=80=20prettier?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.prettierignore | 15 +++++++++++++++
package.json | 1 +
prettier.config.js | 21 +++++++++++++++++++++
src/App.vue | 19 ++++++++++---------
src/types/components.d.ts | 1 -
vite.config.ts | 32 ++++++++++++++++----------------
6 files changed, 63 insertions(+), 26 deletions(-)
create mode 100644 .prettierignore
create mode 100644 prettier.config.js
diff --git a/.prettierignore b/.prettierignore
new file mode 100644
index 00000000..54926961
--- /dev/null
+++ b/.prettierignore
@@ -0,0 +1,15 @@
+# prettier 会忽略的文件
+
+/dist/*
+.local
+.output.js
+/node_modules/**
+
+**/*.svg
+**/*.sh
+
+/public/*
+
+.DS_Store
+*.local
+*.log
diff --git a/package.json b/package.json
index d7e00047..3fb16553 100644
--- a/package.json
+++ b/package.json
@@ -17,6 +17,7 @@
"devDependencies": {
"@types/node": "^17.0.25",
"@vitejs/plugin-vue": "^2.3.1",
+ "prettier": "^2.6.2",
"typescript": "^4.6.3",
"unplugin-auto-import": "^0.7.1",
"unplugin-vue-components": "^0.19.3",
diff --git a/prettier.config.js b/prettier.config.js
new file mode 100644
index 00000000..aaec6a22
--- /dev/null
+++ b/prettier.config.js
@@ -0,0 +1,21 @@
+/** 配置项文档:https://prettier.io/docs/en/configuration.html */
+module.exports = {
+ /** 每一行的宽度 */
+ printWidth: 120,
+ /** tab 健的空格数 */
+ tabWidth: 2,
+ /** 在对象中的括号之间用空格来间隔 */
+ bracketSpacing: true,
+ /** 箭头函数的参数无论有几个,都要括号包裹 */
+ arrowParens: 'always',
+ /** 换行符的使用 */
+ endOfLine: 'auto',
+ /** 采用单引号 */
+ singleQuote: true,
+ /** 对象或者数组的最后一个元素后面是否要加逗号 */
+ trailingComma: 'all',
+ /** 不加分号 */
+ semi: false,
+ /** 不使用 tab 格式化 */
+ useTabs: false,
+}
diff --git a/src/App.vue b/src/App.vue
index 084f3112..1b90cf6e 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,15 +1,16 @@
diff --git a/src/types/components.d.ts b/src/types/components.d.ts
index e534d930..6de580a7 100644
--- a/src/types/components.d.ts
+++ b/src/types/components.d.ts
@@ -5,7 +5,6 @@ import '@vue/runtime-core'
declare module '@vue/runtime-core' {
export interface GlobalComponents {
- ElButton: typeof import('element-plus/es')['ElButton']
HelloWorld: typeof import('./../components/HelloWorld.vue')['default']
}
}
diff --git a/vite.config.ts b/vite.config.ts
index 80f8b4de..4d367bd2 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,9 +1,9 @@
-import { ConfigEnv, UserConfigExport } from "vite"
-import { resolve } from "path"
-import vue from "@vitejs/plugin-vue"
-import AutoImport from "unplugin-auto-import/vite"
-import Components from "unplugin-vue-components/vite"
-import { ElementPlusResolver } from "unplugin-vue-components/resolvers"
+import { ConfigEnv, UserConfigExport } from 'vite'
+import { resolve } from 'path'
+import vue from '@vitejs/plugin-vue'
+import AutoImport from 'unplugin-auto-import/vite'
+import Components from 'unplugin-vue-components/vite'
+import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
/** 配置项文档:https://vitejs.dev/config */
export default (env: ConfigEnv): UserConfigExport => {
@@ -11,7 +11,7 @@ export default (env: ConfigEnv): UserConfigExport => {
resolve: {
alias: {
/** @ 符号指向 src 目录 */
- "@": resolve(__dirname, "./src"),
+ '@': resolve(__dirname, './src'),
},
},
server: {
@@ -29,12 +29,12 @@ export default (env: ConfigEnv): UserConfigExport => {
strictPort: true,
/** 接口代理 */
proxy: {
- "/mock-api": {
- target: "https://vue-typescript-admin-mock-server-armour.vercel.app/mock-api",
+ '/mock-api': {
+ target: 'https://vue-typescript-admin-mock-server-armour.vercel.app/mock-api',
ws: true,
/** 是否允许跨域 */
changeOrigin: true,
- rewrite: (path) => path.replace("/mock-api", ""),
+ rewrite: (path) => path.replace('/mock-api', ''),
},
},
},
@@ -43,26 +43,26 @@ export default (env: ConfigEnv): UserConfigExport => {
/** 消除打包大小超过 500kb 警告 */
chunkSizeWarningLimit: 2000,
/** vite 2.6.x 以上需要配置 minify: terser,terserOptions 才能生效 */
- minify: "terser",
+ minify: 'terser',
/** 在 build 代码时移除 console.log、debugger 和 注释 */
terserOptions: {
compress: {
drop_console: false,
drop_debugger: true,
- pure_funcs: ["console.log"],
+ pure_funcs: ['console.log'],
},
output: {
/** 删除注释 */
comments: false,
},
},
- assetsDir: "static/assets",
+ assetsDir: 'static/assets',
/** 静态资源打包到 dist 下的不同目录 */
rollupOptions: {
output: {
- chunkFileNames: "static/js/[name]-[hash].js",
- entryFileNames: "static/js/[name]-[hash].js",
- assetFileNames: "static/[ext]/[name]-[hash].[ext]",
+ chunkFileNames: 'static/js/[name]-[hash].js',
+ entryFileNames: 'static/js/[name]-[hash].js',
+ assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
},
},
},