Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use unplugin-auto-import #199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions docs/composables.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// generated by iles
// We suggest you to commit this file into source control

// Generated by 'unplugin-auto-import'
export {}
declare global {
const definePageComponent: typeof import('iles')['definePageComponent']
const useDocuments: typeof import('iles')['useDocuments']
const useHead: typeof import('iles')['useHead']
const usePage: typeof import('iles')['usePage']
const useRoute: typeof import('iles')['useRoute']
}

export { }
1 change: 1 addition & 0 deletions packages/iles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"picocolors": "^1.0.0",
"unist-util-visit": "^4.1.0",
"unplugin-vue-components": "^0.21.1",
"unplugin-auto-import": "^0.11.4",
"vite": "^3.2.0",
"vue": "^3.2.37",
"vue-router": "^4.0.12"
Expand Down
16 changes: 16 additions & 0 deletions packages/iles/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import creatDebugger from 'debug'
import { loadConfigFromFile, mergeConfig as mergeViteConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import components from 'unplugin-vue-components/vite'
import composables from 'unplugin-auto-import/vite'
import pages from '@islands/pages'
import mdx from '@islands/mdx'

Expand Down Expand Up @@ -136,6 +137,7 @@ async function setNamedPlugins (config: AppConfig, env: ConfigEnv, plugins: Name
tagName.startsWith('ile-') || ceChecks.some(fn => fn!(tagName))

plugins.components = components(config.components)
plugins.composables = composables(config.composables)
plugins.vue = vue(config.vue)

const optionalPlugins = {
Expand Down Expand Up @@ -281,6 +283,20 @@ function appConfigDefaults (appConfig: AppConfig, userConfig: UserConfig, env: C
],
transformer: 'vue3',
},
composables: {
dts: resolve(root, 'composables.d.ts'),
imports: [
{
iles: [
'definePageComponent',
'useDocuments',
'useHead',
'usePage',
'useRoute',
],
},
],
},
}
}

Expand Down
42 changes: 0 additions & 42 deletions packages/iles/src/node/plugin/composables.ts

This file was deleted.

16 changes: 1 addition & 15 deletions packages/iles/src/node/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { parseId } from './parse'
import { wrapIslandsInSFC, wrapLayout } from './wrap'
import { extendSite } from './site'
import { detectMDXComponents } from './markdown'
import { autoImportComposables, writeComposablesDTS } from './composables'
import documents from './documents'

function isMarkdown (path: string) {
Expand Down Expand Up @@ -63,8 +62,6 @@ export default function IslandsPlugins (appConfig: AppConfig): PluginOption[] {
root = config.root
isBuild = config.command === 'build'
appConfig.resolvePath = config.createResolver()

writeComposablesDTS(root)
},
async resolveId (id) {
if (id === ILES_APP_ENTRY)
Expand Down Expand Up @@ -147,21 +144,10 @@ export default function IslandsPlugins (appConfig: AppConfig): PluginOption[] {
plugins.vue,
...appConfig.vitePlugins,
plugins.components,
plugins.composables,

documents(appConfig),

{
name: 'iles:composables',
enforce: 'post',
async transform (code, id) {
if (!id.startsWith(appConfig.srcDir)) return

const { path, query } = parseId(id)
if (isVueScript(path, query) || /\.[tj]sx?/.test(path))
return await autoImportComposables(code, id)
},
},

{
name: 'iles:page-data',
enforce: 'post',
Expand Down
4 changes: 4 additions & 0 deletions packages/iles/types/shared.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { App, Ref, DefineComponent, VNode, AsyncComponentLoader } from 'vue
import type VuePlugin, { Options as VueOptions } from '@vitejs/plugin-vue'
import type ComponentsPlugin from 'unplugin-vue-components/vite'
import type { Options as ComponentOptions } from 'unplugin-vue-components/types'
import type composablesPlugin from 'unplugin-auto-import/vite'
import type { Options as composablesOptions } from 'unplugin-auto-import/types'

import type { Options as RequiredSolidOptions } from 'vite-plugin-solid'
import type { Options as SvelteOptions } from '@sveltejs/vite-plugin-svelte'
Expand Down Expand Up @@ -107,6 +109,7 @@ export interface NamedPlugins {
pages: { api: PagesApi }
vue: ReturnType<typeof VuePlugin>
components: ReturnType<typeof ComponentsPlugin>
composables: ReturnType<typeof composablesPlugin>
}

export interface SSGContext {
Expand All @@ -128,6 +131,7 @@ export interface BaseIlesConfig extends PagesOptions {
* imports for components in Vue and MDX files.
*/
components: ComponentOptions
composables: composablesOptions
/**
* Configuration options for @preact/preset-vite
*/
Expand Down
7 changes: 2 additions & 5 deletions playground/the-vue-point/composables.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// generated by iles
// We suggest you to commit this file into source control

// Generated by 'unplugin-auto-import'
export {}
declare global {
const definePageComponent: typeof import('iles')['definePageComponent']
const useDocuments: typeof import('iles')['useDocuments']
const useHead: typeof import('iles')['useHead']
const usePage: typeof import('iles')['usePage']
const useRoute: typeof import('iles')['useRoute']
}

export { }
Loading