Skip to content

Commit

Permalink
fix: supress Vite out dir warning
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Jul 10, 2024
1 parent cb98324 commit baf83d3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 63 deletions.
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
"typesVersions": {
"*": {
"config": [
"./dist/client/config.d.mts"
"./dist/client/config.d.ts"
],
"plugin": [
"./dist/client/plugin.d.mts"
"./dist/client/plugin.d.ts"
]
}
},
Expand Down Expand Up @@ -104,10 +104,5 @@
"typescript": "^5.5.3",
"unbuild": "^3.0.0-rc.6",
"vitest": "^2.0.1"
},
"pnpm": {
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
}
}
}
21 changes: 0 additions & 21 deletions patches/[email protected]

This file was deleted.

53 changes: 24 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 28 additions & 6 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { basename, dirname, resolve } from 'pathe'
import { consola } from 'consola'
import { colors } from 'consola/utils'
import { debounce } from 'perfect-debounce'
import { build as _build, createServer, mergeConfig } from 'vite'
import { build as _build, createLogger, createServer, mergeConfig } from 'vite'
import * as vueCompilerSfc from 'vue/compiler-sfc'
import vuePlugin from '@vitejs/plugin-vue2'
import vueJsxPlugin from '@vitejs/plugin-vue2-jsx'
Expand All @@ -24,9 +24,22 @@ import type { BaseOptions, BuildOptions, PostCSSConfigResult, ServeOptions, User
let resolvedKirbyupConfig: UserConfig
let resolvedPostCssConfig: PostCSSConfigResult

function getViteConfig<T extends 'build' | 'serve'>(
command: T,
options: T extends 'build' ? BuildOptions : ServeOptions,
const logger = createLogger()
const loggerWarn = logger.warn

logger.warn = (msg, options) => {
// Ignore output directory warning for Kirby plugin builds
if (msg.startsWith(`\n(!) build.outDir must not be`))
return

loggerWarn(msg, options)
}

function getViteConfig(command: 'build', options: BuildOptions): InlineConfig
function getViteConfig(command: 'serve', options: ServeOptions): InlineConfig
function getViteConfig(
command: string,
options: BuildOptions | ServeOptions,
): InlineConfig {
const aliasDir = resolve(options.cwd, dirname(options.entry))
const { alias = {}, vite, extendViteConfig } = resolvedKirbyupConfig
Expand All @@ -50,6 +63,7 @@ function getViteConfig<T extends 'build' | 'serve'>(
],
css: { postcss: resolvedPostCssConfig },
envPrefix: ['VITE_', 'KIRBYUP_'],
customLogger: logger,
logLevel: 'warn',
}

Expand All @@ -62,9 +76,17 @@ function getViteConfig<T extends 'build' | 'serve'>(
watch && fullReloadPlugin(watch),
].filter(Boolean),
// Input needs to be specified so dependency pre-bundling works
build: { rollupOptions: { input: resolve(options.cwd, options.entry) } },
build: {
rollupOptions: {
input: resolve(options.cwd, options.entry),
},
},
// Specify origin so asset URLs include Vite server host
server: { port, strictPort: true, origin: `http://localhost:${port}` },
server: {
port,
strictPort: true,
origin: `http://localhost:${port}`,
},
})

return mergeConfig(serveConfig, userConfig)
Expand Down

0 comments on commit baf83d3

Please sign in to comment.