Skip to content

Commit 27c29e4

Browse files
authored
refactor: move vite config and shared plugins to config (#4069)
Moves the common parts of the vite config to a base config exposed by the config package. The different configs don't depend on each other anymore but each extends the base config individually. Also the common plugin configs are moved to the config package and each vite config imports the plugin configs. Also as the `vite.config.development` just imported and reexported the production config, I have removed it. --------- Signed-off-by: schogges <moritz.fleck@konghq.com>
1 parent dc9d87a commit 27c29e4

16 files changed

Lines changed: 124 additions & 120 deletions

File tree

package-lock.json

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/config/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"vitepress": "^2.0.0-alpha.8",
6060
"vitest": "^3.2.4",
6161
"vue-tsc": "^2.2.12",
62+
"@types/markdown-it": "^14.1.2",
6263
"deepmerge": "^4.3.1",
6364
"js-yaml": "^4.1.0"
6465
}

packages/config/src/mk/build.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build/preview: VITE ?= $(shell $(MAKE) resolve/bin BIN=vite)
1111
build/preview:
1212
@$(VITE) \
1313
--configLoader runner \
14-
-c ./vite.config.development.ts \
14+
-c ./vite.config.production.ts \
1515
--mode preview \
1616
build
1717

packages/config/src/mk/run.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.run: install
44
@$(VITE) \
55
--configLoader runner \
6-
-c ./vite.config.development.ts
6+
-c ./vite.config.production.ts
77

88
.PHONY: .run/docs
99
.run/docs: VITEPRESS ?= $(shell $(MAKE) resolve/bin BIN=vitepress)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './vite.config.base'
2+
export * from './utils'
File renamed without changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/// <reference types="vitest/config" />
2+
import path from 'node:path'
3+
4+
import { hoistUseStatements } from '.'
5+
import type { UserConfig, UserConfigFn } from 'vite'
6+
7+
8+
export const defineConfig: UserConfigFn = () => ({
9+
base: './',
10+
server: {
11+
port: 8080,
12+
},
13+
resolve: {
14+
alias: {
15+
/**
16+
* Used to import files using, for example, '@/api/kumaApi'.
17+
*/
18+
'@': path.resolve(process.cwd(), 'src'),
19+
},
20+
},
21+
css: {
22+
preprocessorOptions: {
23+
scss: {
24+
additionalData: hoistUseStatements(`
25+
@use "@kong/design-tokens/tokens/scss/variables" as *;
26+
`),
27+
api: 'modern-compiler',
28+
},
29+
},
30+
},
31+
32+
test: {
33+
globals: false,
34+
environment: 'jsdom',
35+
setupFiles: [
36+
path.resolve(process.cwd(), './test-support/main.ts'),
37+
],
38+
deps: {
39+
optimizer: {
40+
web: {
41+
// https://github.com/vitest-dev/vitest/issues/4074
42+
exclude: ['vue'],
43+
},
44+
},
45+
},
46+
include: [
47+
'**/src/**/*.spec.ts',
48+
],
49+
exclude: [
50+
'**/dist/**',
51+
'**/node_modules/**',
52+
],
53+
},
54+
}) satisfies UserConfig

packages/config/src/vite/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './plugins'
2+
export * from './config'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './server'
2+
export * from './plugins'
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { DEFAULT_SCHEMA, Type } from 'js-yaml'
2+
import markdown from 'markdown-it'
3+
4+
export const yamlLoaderPluginConfig = () => {
5+
const md = markdown(
6+
{
7+
html: true,
8+
},
9+
)
10+
return {
11+
schema: DEFAULT_SCHEMA.extend(
12+
new Type('tag:yaml.org,2002:text/markdown', {
13+
kind: 'scalar',
14+
construct: (data) => {
15+
// We only currently use !!text/markdown within yaml for out locales/i18n text
16+
// for which we use FormatJS under the hood. FormatJS requires you to escape any XML/HTML looking
17+
// things, plus ICU '{' and '}', hence this replace.
18+
// If we ever need !!text/markdown for anything else we should do something like !!text/icu+markdown
19+
const str = md.render(data)
20+
21+
return str.replace(/</g, "'<'")
22+
.replace(/%7B/g, '{')
23+
.replace(/%7D/g, '}')
24+
},
25+
}),
26+
),
27+
}
28+
}
29+
30+
export const vuePluginConfig = () => ({
31+
template: {
32+
compilerOptions: {
33+
whitespace: 'preserve' as const,
34+
isCustomElement: (item: string) => [
35+
'search',
36+
].includes(item),
37+
},
38+
},
39+
})

0 commit comments

Comments
 (0)