mirror of https://github.com/YunYouJun/valaxy
fix: repeated vite.config.ts caused by vite auto load vuserRoot config
This commit is contained in:
parent
7c9f1c600d
commit
1e0d8e323b
|
@ -13,3 +13,5 @@ dist-ssr
|
|||
node_modules
|
||||
.idea/
|
||||
*.log
|
||||
|
||||
components.d.ts
|
||||
|
|
|
@ -10,9 +10,7 @@ declare module '@vue/runtime-core' {
|
|||
404: typeof import('./../packages/valaxy-theme-press/layouts/404.vue')['default']
|
||||
AppLink: typeof import('./../packages/valaxy/client/components/AppLink.vue')['default']
|
||||
Default: typeof import('./../packages/valaxy-theme-press/layouts/default.vue')['default']
|
||||
Docs: typeof import('./../packages/valaxy-theme-press/layouts/docs.vue')['default']
|
||||
DocsBoard: typeof import('./../packages/valaxy-theme-press/components/DocsBoard.vue')['default']
|
||||
DocsHome: typeof import('./../packages/valaxy-theme-press/components/DocsHome.vue')['default']
|
||||
Home: typeof import('./../packages/valaxy-theme-press/layouts/home.vue')['default']
|
||||
Layout: typeof import('./../packages/valaxy-theme-press/layouts/layout.vue')['default']
|
||||
Post: typeof import('./../packages/valaxy-theme-press/layouts/post.vue')['default']
|
||||
|
@ -26,7 +24,6 @@ declare module '@vue/runtime-core' {
|
|||
PressDate: typeof import('./../packages/valaxy-theme-press/components/PressDate.vue')['default']
|
||||
PressFeature: typeof import('./../packages/valaxy-theme-press/components/PressFeature.vue')['default']
|
||||
PressFeatures: typeof import('./../packages/valaxy-theme-press/components/PressFeatures.vue')['default']
|
||||
PressHeader: typeof import('./../packages/valaxy-theme-press/components/PressHeader.vue')['default']
|
||||
PressHome: typeof import('./../packages/valaxy-theme-press/components/PressHome.vue')['default']
|
||||
PressHomeFeatures: typeof import('./../packages/valaxy-theme-press/components/PressHomeFeatures.vue')['default']
|
||||
PressHomeHero: typeof import('./../packages/valaxy-theme-press/components/PressHomeHero.vue')['default']
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"module": "ESNext",
|
||||
"target": "ESNext",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"jsx": "preserve",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"noUnusedLocals": true,
|
||||
"strictNullChecks": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"exclude": ["dist", "node_modules"]
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
import { defineConfig } from 'vite'
|
||||
|
||||
const safelist = [
|
||||
'i-ri-home-line',
|
||||
]
|
||||
|
||||
export default defineConfig({
|
||||
base: '/',
|
||||
plugins: [],
|
||||
valaxy: {
|
||||
unocss: {
|
||||
safelist,
|
||||
},
|
||||
|
||||
markdown: {
|
||||
blocks: {
|
||||
tip: {
|
||||
icon: 'i-carbon-thumbs-up',
|
||||
text: 'ヒント',
|
||||
},
|
||||
warning: {
|
||||
icon: 'i-carbon-warning-alt',
|
||||
text: '注意',
|
||||
},
|
||||
danger: {
|
||||
icon: 'i-carbon-warning',
|
||||
text: '警告',
|
||||
},
|
||||
info: {
|
||||
text: 'información',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
|
@ -1,6 +1,7 @@
|
|||
<script lang="ts" setup>
|
||||
import { computed } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { EXTERNAL_URL_RE } from 'valaxy'
|
||||
|
||||
const props = defineProps<{
|
||||
theme: 'brand' | 'alt'
|
||||
|
@ -8,6 +9,7 @@ const props = defineProps<{
|
|||
text: string
|
||||
}>()
|
||||
|
||||
const isUrl = computed(() => EXTERNAL_URL_RE.test(props.link))
|
||||
const router = useRouter()
|
||||
|
||||
const classes = computed(() => {
|
||||
|
@ -22,12 +24,15 @@ const classes = computed(() => {
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<button
|
||||
<component
|
||||
:is="isUrl ? 'a' : 'button'"
|
||||
m="2"
|
||||
:class="classes"
|
||||
class="sese-btn btn" bg="gradient-to-r"
|
||||
@click="router.push(link)"
|
||||
:href="isUrl ? link : undefined"
|
||||
:target="isUrl ? '_blank' : undefined"
|
||||
@click="!isUrl && router.push(link)"
|
||||
>
|
||||
{{ text }}
|
||||
</button>
|
||||
</component>
|
||||
</template>
|
||||
|
|
|
@ -22,11 +22,11 @@ defineProps<{
|
|||
|
||||
<style scoped>
|
||||
.press-feature {
|
||||
border: 1px solid var(--vp-c-bg-soft);
|
||||
border: 1px solid var(--va-c-bg-soft);
|
||||
border-radius: 12px;
|
||||
padding: 24px;
|
||||
height: 100%;
|
||||
background-color: var(--vp-c-bg-soft);
|
||||
background-color: var(--va-c-bg-soft);
|
||||
}
|
||||
|
||||
.icon {
|
||||
|
|
|
@ -17,7 +17,7 @@ const grid = computed(() => {
|
|||
|
||||
<template>
|
||||
<div class="press-features">
|
||||
<div class="container grid" :class="[grid]">
|
||||
<div class="container grid gap-4" :class="[grid]">
|
||||
<div v-for="feature in features" :key="feature.title" class="inline-grid">
|
||||
<PressFeature :feature="feature" />
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script lang="ts" setup>
|
||||
import { useConfig } from 'valaxy'
|
||||
import { isDark, toggleDark, useConfig } from 'valaxy'
|
||||
import { computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useThemeConfig } from '../composables'
|
||||
|
@ -33,6 +33,11 @@ const themeConfig = useThemeConfig()
|
|||
|
||||
<span v-if="i !== themeConfig.nav.length - 1" class="mr-2 ml-2">·</span>
|
||||
</template>
|
||||
|
||||
<button type="button" aria-label="Toggle Dark Mode" @click="toggleDark()">
|
||||
<div v-if="!isDark" i-ri-sun-line />
|
||||
<div v-else i-ri-moon-line />
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
</template>
|
||||
|
|
|
@ -53,6 +53,8 @@ $light: map.merge(
|
|||
"c-bg": white,
|
||||
"c-bg-light": white,
|
||||
"c-bg-dark": #fafafa,
|
||||
|
||||
"c-bg-soft": white,
|
||||
"c-bg-alt": #f9f9f9,
|
||||
"c-bg-mute": #f1f1f1,
|
||||
|
||||
|
@ -81,8 +83,10 @@ $dark: map.merge(
|
|||
"c-bg": #1a1a1a,
|
||||
"c-bg-light": #1d1e1f,
|
||||
"c-bg-dark": #1a1a1a,
|
||||
"c-bg-alt": #1a1a1a,
|
||||
|
||||
"c-bg-soft": #1d1e1f,
|
||||
"c-bg-mute": #2f2f2f,
|
||||
"c-bg-alt": #1a1a1a,
|
||||
|
||||
"c-text": #f2f2f2,
|
||||
"c-text-light": #ddd,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
export const EXTERNAL_URL_RE = /^https?:/i
|
||||
|
||||
/**
|
||||
* 生成介于 min 与 max 之间的随机数
|
||||
* @returns
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
import { defineConfig } from 'vite'
|
||||
|
||||
export default defineConfig({})
|
|
@ -67,6 +67,8 @@ cli.command(
|
|||
const options = await resolveOptions({ userRoot: root })
|
||||
|
||||
const viteConfig: InlineConfig = {
|
||||
// avoid load userRoot/vite.config.ts repeatedly
|
||||
configFile: path.resolve(options.clientRoot, 'vite.config.ts'),
|
||||
server: {
|
||||
watch: {
|
||||
// watch theme updated
|
||||
|
@ -140,6 +142,8 @@ cli.command(
|
|||
const viteConfig = mergeConfig(
|
||||
await mergeViteConfigs(options, 'build'),
|
||||
{
|
||||
// avoid load userRoot/vite.config.ts repeatedly
|
||||
configFile: path.resolve(options.clientRoot, 'vite.config.ts'),
|
||||
base,
|
||||
build: {
|
||||
// make out dir empty, https://vitejs.dev/config/#build-emptyoutdir
|
||||
|
|
|
@ -6,7 +6,7 @@ import { loadConfigFromFile, mergeConfig } from 'vite'
|
|||
import type { ResolvedValaxyOptions } from './options'
|
||||
import { toAtFS } from './utils'
|
||||
|
||||
export async function mergeViteConfigs({ themeRoot }: ResolvedValaxyOptions, command: 'serve' | 'build') {
|
||||
export async function mergeViteConfigs({ userRoot, themeRoot }: ResolvedValaxyOptions, command: 'serve' | 'build') {
|
||||
const configEnv: ConfigEnv = {
|
||||
mode: 'development',
|
||||
command,
|
||||
|
@ -14,9 +14,9 @@ export async function mergeViteConfigs({ themeRoot }: ResolvedValaxyOptions, com
|
|||
|
||||
let resolvedConfig: InlineConfig = {}
|
||||
|
||||
// userRoot vite.config.ts had been auto loaded by vite
|
||||
// let vite default config file be clientRoot/vite.config.ts
|
||||
const files = uniq([
|
||||
// userRoot,
|
||||
userRoot,
|
||||
themeRoot,
|
||||
]).map(i => join(i, 'vite.config.ts'))
|
||||
|
||||
|
|
|
@ -161,6 +161,6 @@ export async function resolveConfig(options: ValaxyEntryOptions = {}) {
|
|||
export type ThemeConfigExport = ValaxyThemePlugin | Promise<ValaxyThemePlugin> | ThemeConfigFn
|
||||
export type ThemeConfigFn = (options: ResolvedValaxyOptions) => ValaxyThemePlugin | Promise<ValaxyThemePlugin>
|
||||
|
||||
export async function defineThemePlugin(config: ThemeConfigExport) {
|
||||
export function defineThemePlugin(config: ThemeConfigExport) {
|
||||
return config
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ export async function ViteValaxyPlugins(
|
|||
|
||||
// for render markdown excerpt
|
||||
const mdIt = new MarkdownIt({ html: true })
|
||||
|
||||
await setupMarkdownPlugins(mdIt, pluginOptions.markdown, true)
|
||||
|
||||
const customElements = new Set([
|
||||
|
|
|
@ -5,7 +5,7 @@ import { mergeConfig as mergeViteConfig } from 'vite'
|
|||
|
||||
export async function resolveValaxyConfig(options: ResolvedValaxyOptions, viteConfig: InlineConfig = {}) {
|
||||
const { default: config } = (await import(`valaxy-theme-${options.theme}`))
|
||||
let resolved = typeof config === 'function' ? (await config?.(options)) : await config
|
||||
let resolved = typeof config === 'function' ? (await config?.(options)) : config
|
||||
|
||||
if (!resolved)
|
||||
return {}
|
||||
|
|
Loading…
Reference in New Issue