Skip to content

Commit

Permalink
autoimport updates
Browse files Browse the repository at this point in the history
  • Loading branch information
solmanter committed Mar 21, 2023
1 parent dfe002d commit 0564bca
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
23 changes: 21 additions & 2 deletions config/dirs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
import { source, utilsAutoImport, type UtilTypes } from './structures'

// ./src/app/{path}/shared
export const RootDirs: string[] = ['examples/full', 'examples/minimal'].map(
(dir) => `./src/app/${dir}/shared`
const ROOT_FOLDER = '@/app/'

function rootPath(dir: string, extention?: string) {
if (extention) return `${ROOT_FOLDER}${dir}/${extention}`
return `${ROOT_FOLDER}${dir}`
}

// For auto importing components
export const AutoImportComponents: string[] = source.map((dir) => [rootPath(dir, 'shared')]).flat(1)

type ReturnUtilsType = { [x: string]: string[] }

// For auto importing functions, stores ...
export const AutoImportUtils: ReturnUtilsType = Object.keys(utilsAutoImport).reduce(
(acc, util: any) => {
;(acc as any)[rootPath(util)] = utilsAutoImport[util as UtilTypes]
return acc
},
{} as ReturnUtilsType
)
8 changes: 8 additions & 0 deletions config/structures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export let source = ['examples/full', 'examples/minimal'];

export const utilsAutoImport = {
'examples/minimal/stores': ['useExampleStore']
}

export type UtilTypes = keyof typeof utilsAutoImport;
1 change: 0 additions & 1 deletion src/app/examples/minimal/example.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import Counter from './components/counter.vue'
import { useExampleStore } from './stores/example'
const exampleStore = useExampleStore()
</script>
Expand Down
1 change: 1 addition & 0 deletions src/app/examples/minimal/stores/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './example';
7 changes: 4 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver, NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import Terminal from 'vite-plugin-terminal'
import { RootDirs } from './config/dirs'
import { AutoImportComponents, AutoImportUtils } from './config/dirs'

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -19,7 +19,7 @@ export default defineConfig({
}),
Components({
dts: true,
dirs: [...RootDirs],
dirs: [...AutoImportComponents],
resolvers: [ElementPlusResolver(), NaiveUiResolver()],
directoryAsNamespace: false
}),
Expand All @@ -32,7 +32,8 @@ export default defineConfig({
'virtual:terminal': ['terminal'],
'@vueuse/core': ['useMouse'],
pinia: ['defineStore', 'setActivePinia', 'createPinia'],
'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar']
'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar'],
...AutoImportUtils
}
],
include: [/\.[jt]sx?$/, /\.vue\??/],
Expand Down

2 comments on commit 0564bca

@vercel
Copy link

@vercel vercel bot commented on 0564bca Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks for Deployment have failed

vue-advanced-starter – ./

@vercel
Copy link

@vercel vercel bot commented on 0564bca Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.