Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit ada2caa

Browse files
committed
feat: import build process
1 parent 30a8702 commit ada2caa

File tree

17 files changed

+230
-243
lines changed

17 files changed

+230
-243
lines changed

modules/nuxt/build.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineBuildConfig } from "unbuild"
2+
3+
export default defineBuildConfig({
4+
declaration: true,
5+
entries: [
6+
"src/module",
7+
{ input: "src/runtime/", outDir: `dist/runtime`, ext: "mjs" },
8+
],
9+
failOnWarn: false,
10+
})

modules/nuxt/chakra-shims.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import type * as Chakra from "@chakra-ui/vue-next"

modules/nuxt/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
},
1111
"main": "./dist/module.cjs",
12-
"types": "./dist/types.d.ts",
12+
"types": "./dist/module.d.ts",
1313
"files": [
1414
"dist"
1515
],
@@ -30,7 +30,8 @@
3030
"@chakra-ui/vue-next": "workspace:*",
3131
"@emotion/css": "^11.10.5",
3232
"@emotion/server": "^11.10.0",
33-
"@nuxtjs/emotion": "1.0.0"
33+
"@nuxtjs/emotion": "1.0.0",
34+
"unbuild": "^1.1.1"
3435
},
3536
"peerDependencies": {
3637
"vue": "^3.1.4"

modules/nuxt/playground/app.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</template>
2727

2828
<script lang="ts" setup>
29-
import { chakra, useColorMode } from "@chakra-ui/vue-next"
29+
import { chakra, useColorMode, CHStack } from "@chakra-ui/vue-next"
3030
3131
const { colorMode, toggleColorMode } = useColorMode()
3232
</script>

modules/nuxt/playground/nuxt.config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import type * as NuxtSchema from "@nuxt/schema"
55
export default defineNuxtConfig({
66
ssr: true,
77
modules: [chakraModule],
8-
// chakra: {
9-
// extendTheme: {
10-
// colors: {
11-
// $brand: "#f5f",
12-
// },
13-
// },
14-
// },
8+
chakra: {
9+
extendTheme: {
10+
colors: {
11+
$brand: "#f5f",
12+
},
13+
},
14+
},
1515
})

modules/nuxt/src/module.ts

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
createResolver,
55
addServerPlugin,
66
installModule,
7-
addPluginTemplate,
87
addComponent,
98
} from "@nuxt/kit"
109
import type * as NuxtSchema from "@nuxt/schema"
@@ -14,7 +13,6 @@ import {
1413
extendTheme as _extendTheme,
1514
} from "@chakra-ui/vue-next"
1615
import { mergeWith } from "@chakra-ui/utils"
17-
import * as ChakraComponents from "@chakra-ui/vue-next"
1816

1917
/** Chakra UI Vue SSR Context State */
2018
export interface ChakraUISSRContext {
@@ -29,31 +27,17 @@ declare global {
2927
}
3028
}
3129

32-
function getChakraComponents() {
33-
const Components = []
34-
const _ChakraComponents = ChakraComponents as Record<string, any>
35-
for (const component in _ChakraComponents) {
36-
/**
37-
* Group of strict checks to make sure that
38-
* we only generate types for components.
39-
*/
40-
if (
41-
component.startsWith("C") &&
42-
_ChakraComponents[component]?.name &&
43-
_ChakraComponents[component]?.setup &&
44-
typeof _ChakraComponents[component]?.setup === "function"
45-
) {
46-
Components.push(_ChakraComponents[component])
47-
}
48-
}
49-
50-
return Components
51-
}
5230
export type ChakraModuleOptions = Omit<ChakraPluginOptions, "colorModeManager">
5331

5432
const defaultModuleOptions: ChakraModuleOptions = {
5533
cssReset: true,
56-
isBaseTheme: false,
34+
isBaseTheme: true,
35+
}
36+
37+
declare module "@nuxt/schema" {
38+
interface AppConfig {
39+
$chakraConfig: ChakraModuleOptions
40+
}
5741
}
5842

5943
export default defineNuxtModule<ChakraModuleOptions>({
@@ -77,37 +61,22 @@ export default defineNuxtModule<ChakraModuleOptions>({
7761

7862
nuxt.options.build.transpile.push("@chakra-ui")
7963

64+
nuxt.options.appConfig.$chakraConfig = {
65+
extendTheme,
66+
isBaseTheme,
67+
icons,
68+
cssReset,
69+
emotionCacheOptions,
70+
}
71+
8072
// Install emotion module
8173
installModule("@nuxtjs/emotion")
8274
const { resolve } = createResolver(import.meta.url)
8375
const runtimeDir = resolve("./runtime")
8476
nuxt.options.build.transpile.push(runtimeDir)
8577

86-
for (const Component of getChakraComponents()) {
87-
addComponent({
88-
name: Component.name,
89-
export: Component.name,
90-
filePath: "@chakra-ui/vue-next",
91-
})
92-
}
93-
9478
// Resolve template and inject plugin
9579
addPlugin(resolve(runtimeDir, "chakra"))
9680
addServerPlugin(resolve(runtimeDir, "chakra.server"))
97-
// addPluginTemplate(
98-
// {
99-
// src: resolve(runtimeDir, "templates/chakra.universal.t.js"),
100-
// options: {
101-
// extendTheme,
102-
// cssReset,
103-
// icons,
104-
// emotionCacheOptions,
105-
// isBaseTheme,
106-
// } as ChakraPluginOptions,
107-
// },
108-
// {
109-
// append: true,
110-
// }
111-
// )
11281
},
11382
})

modules/nuxt/src/runtime/chakra.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type * as NuxtAppTypes from "nuxt/app"
2-
import { defineNuxtPlugin } from "#imports"
2+
import { defineNuxtPlugin, useAppConfig } from "#imports"
33
import Chakra, {
44
chakra,
55
cookieStorageManagerSSR,
@@ -10,16 +10,26 @@ import Chakra, {
1010
} from "@chakra-ui/vue-next"
1111
import { domElements } from "@chakra-ui/vue-system"
1212
import { parseCookies } from "h3"
13+
import type { ChakraModuleOptions } from "../module"
1314

1415
type AllowedSSRColorMode = Exclude<
1516
ColorModeScriptProps["initialColorMode"],
1617
"system"
1718
>
1819

20+
declare module "@nuxt/schema" {
21+
interface App {
22+
$chakraConfig: ChakraModuleOptions
23+
}
24+
}
25+
1926
export default defineNuxtPlugin((nuxtApp) => {
2027
const app = nuxtApp.vueApp
2128
const isBrowser = typeof document !== "undefined"
2229

30+
const config = useAppConfig()
31+
const chakraConfig = config.$chakraConfig
32+
2333
// SSR Color Mode Handling
2434
let ssrColorMode
2535
const event = nuxtApp.ssrContext?.event
@@ -39,10 +49,21 @@ export default defineNuxtPlugin((nuxtApp) => {
3949
app.use(
4050
Chakra,
4151
extendChakra({
42-
cssReset: true,
52+
...(chakraConfig.emotionCacheOptions && {
53+
emotionCacheOptions: chakraConfig.emotionCacheOptions,
54+
}),
55+
...(chakraConfig.cssReset && {
56+
cssReset: chakraConfig.cssReset,
57+
}),
4358
extendTheme: extendTheme({
44-
colors: {
45-
$brand: "#f5f",
59+
...(chakraConfig.extendTheme && chakraConfig.extendTheme),
60+
config: {
61+
...(chakraConfig.extendTheme?.config && {
62+
extendTheme: chakraConfig.extendTheme.config,
63+
}),
64+
initialColorMode: isBrowser
65+
? window.$chakraSSRContext?.theme?.ssrColorMode
66+
: ssrColorMode,
4667
},
4768
}),
4869
colorModeManager: cookieStorageManagerSSR(

modules/nuxt/src/runtime/templates/chakra.universal.t.js

Lines changed: 0 additions & 91 deletions
This file was deleted.

modules/nuxt/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
// "extends": "../../tsconfig.json",
33
"extends": "./playground/.nuxt/tsconfig.json",
4-
"include": ["src", "./index.tsx", "./index.ts"],
5-
"exclude": ["src/templates"]
4+
"include": ["src", "./index.tsx", "./index.ts", "chakra-shims.d.ts"],
65
}

packages/c-accordion/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "2.0.0-beta.1",
44
"main": "dist/chakra-ui-c-accordion.cjs.js",
55
"module": "dist/chakra-ui-c-accordion.esm.js",
6-
"typings": "dist/chakra-ui-c-accordion.d.ts",
76
"files": [
87
"dist"
98
],

0 commit comments

Comments
 (0)