feat: 新增[unplugin-auto-import] 自动导入

This commit is contained in:
h_mo 2023-05-20 18:43:22 +08:00
parent ff4b1f9278
commit 26f1911ff2
13 changed files with 44 additions and 23 deletions

View File

@ -19,7 +19,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
},
/**定义文件继承的子规范 */
extends: ['eslint:recommended', 'plugin:vue/vue3-essential', 'plugin:@typescript-eslint/recommended'],
extends: ['eslint:recommended', 'plugin:vue/vue3-essential', 'plugin:@typescript-eslint/recommended','./.eslintrc-auto-import.json'],
plugins: ['vue', '@typescript-eslint'],
rules: {
'no-var': 'error', //要求使用 let 或 const 而不是 var

2
.gitignore vendored
View File

@ -9,3 +9,5 @@
**/*.tsbuildinfo
.eslintcache
pnpm-lock.yaml
/.eslintrc-auto-import.json
/typings/

View File

@ -89,6 +89,7 @@
"uni-read-pages-vite": "^0.0.6",
"unocss": "^0.51.13",
"unocss-preset-weapp": "^0.6.3",
"unplugin-auto-import": "^0.16.0",
"vite": "^4.3.7"
}
}

View File

@ -1,10 +1,7 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import BasicButton from '@/components/BasicButton/index.vue';
import AppProvider from '@/components/AppProvider/inedx.vue';
import { useAuthStore } from '@/state/modules/auth';
import { useRouter } from 'uni-mini-router';
onLoad(() => {
console.log('about load');

View File

@ -1,7 +1,6 @@
<script lang="ts" setup>
import BasicButton from '@/components/BasicButton/index.vue';
import AppProvider from '@/components/AppProvider/inedx.vue';
import { useRouter } from 'uni-mini-router';
const router = useRouter();
const jumpList1 = () => {

View File

@ -1,8 +1,6 @@
<script setup lang="ts">
import { ref } from 'vue';
import BasicButton from '@/components/BasicButton/index.vue';
import AppProvider from '@/components/AppProvider/inedx.vue';
import { useRouter } from 'uni-mini-router';
import { CURRENT_PLATFORM, PLATFORMS } from '@/enums/platformEnum';
import { judgePlatform } from '@/utils/platform';
import Iconify from '@/components/Iconify/index.vue';

View File

@ -1,6 +1,4 @@
<script lang="ts" setup>
import { onLoad } from '@dcloudio/uni-app';
onLoad((query) => {
console.log('log onLoad query', query);
});

View File

@ -1,12 +1,10 @@
<script setup lang="ts">
import { reactive, ref, unref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { useAuthStore } from '@/state/modules/auth';
import { Toast } from '@/utils/uniapi/prompt';
import { useRouter } from 'uni-mini-router';
import { useRequest } from 'alova';
// import { useRequest } from 'alova';
import { login } from '@/services/api/auth';
import { omit } from 'lodash-es';
import { useRequest } from 'alova';
const pageQuery = ref<Record<string, any> | undefined>(undefined);
onLoad((query) => {

View File

@ -1,8 +1,6 @@
<script lang="ts" setup>
import { onLoad } from '@dcloudio/uni-app';
import { ref } from 'vue';
import BasicButton from '@/components/BasicButton/index.vue';
import { useRouter } from 'uni-mini-router';
const go = ref<string>('');
const router = useRouter();

View File

@ -1,6 +1,5 @@
<script lang="ts" setup>
import BasicButton from '@/components/BasicButton/index.vue';
import { useRouter } from 'uni-mini-router';
const router = useRouter();
const jumpTest2 = () => {

View File

@ -1,6 +1,5 @@
<script lang="ts" setup>
import BasicButton from '@/components/BasicButton/index.vue';
import { useRouter } from 'uni-mini-router';
const router = useRouter();
const jumpDetail = () => {

View File

@ -1,5 +1,13 @@
{
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "vite.config.*"], //
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue",
"vite.config.*",
"typings/*.ts",
"typings/*.d.ts"
], //
"exclude": [], //
"compilerOptions": {
"baseUrl": "./", //
@ -10,7 +18,7 @@
"moduleResolution": "node", // TypeScript
"esModuleInterop": true, // export=import from
"lib": ["ESNext", "DOM", "ScriptHost"], // TS
"types": ["@dcloudio/types", "@types/node"], //
"types": ["@types/node"], //
"removeComments": true, //
"paths": { "@/*": ["./src/*"] }, //
"pretty": true, // 使

View File

@ -3,7 +3,8 @@ import { ConfigEnv, loadEnv, UserConfig } from 'vite';
import { resolve } from 'path';
import uni from '@dcloudio/vite-plugin-uni';
import Unocss from 'unocss/vite';
import TransformPages from 'uni-read-pages-vite';
import TransformPages from 'uni-read-pages-vite'; // vite.config.ts
import AutoImport from 'unplugin-auto-import/vite';
export default ({ mode }: ConfigEnv): UserConfig => {
const root = process.cwd();
@ -20,7 +21,7 @@ export default ({ mode }: ConfigEnv): UserConfig => {
// 自定义全局变量
define: {
'process.env': {},
ROUTES: (new TransformPages()).routes,
ROUTES: new TransformPages().routes,
},
// 开发服务器配置
server: {
@ -58,6 +59,29 @@ export default ({ mode }: ConfigEnv): UserConfig => {
},
},
// 插件
plugins: [uni(), Unocss()],
plugins: [
uni(),
Unocss(),
// 自动导入
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/, // .vue
],
imports: [
'vue',
'uni-app',
'pinia',
{
'uni-mini-router': ['useRouter', 'useRoute'],
},
],
dts: 'typings/auto-imports.d.ts',
eslintrc: {
enabled: true,
},
}),
],
};
};