mirror of
https://gitee.com/h_mo/uniapp-vue3-vite-ts-template
synced 2025-04-05 06:12:44 +08:00
feat: 新增[unplugin-auto-import] 自动导入
This commit is contained in:
parent
ff4b1f9278
commit
26f1911ff2
@ -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
2
.gitignore
vendored
@ -9,3 +9,5 @@
|
||||
**/*.tsbuildinfo
|
||||
.eslintcache
|
||||
pnpm-lock.yaml
|
||||
/.eslintrc-auto-import.json
|
||||
/typings/
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
|
@ -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 = () => {
|
||||
|
@ -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';
|
||||
|
@ -1,6 +1,4 @@
|
||||
<script lang="ts" setup>
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
|
||||
onLoad((query) => {
|
||||
console.log('log onLoad query', query);
|
||||
});
|
||||
|
@ -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) => {
|
||||
|
@ -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();
|
||||
|
@ -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 = () => {
|
||||
|
@ -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 = () => {
|
||||
|
@ -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, // 在输出中启用颜色和格式,使编译器错误更容易阅读
|
||||
|
@ -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,
|
||||
},
|
||||
}),
|
||||
],
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user