Skip to content

Commit f606398

Browse files
committed
chore: use klona and content configuration as object
1 parent 419eaea commit f606398

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"consola": "^3.2.3",
5050
"defu": "^6.1.4",
5151
"h3": "^1.12.0",
52+
"klona": "^2.0.6",
5253
"pathe": "^1.1.2",
5354
"postcss": "^8.4.38",
5455
"postcss-nesting": "^12.1.5",

playground/nuxt.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@ const logger = consola.withTag('nuxt:tailwindcss:playground')
1111

1212
export default defineNuxtConfig({
1313
extends: ['./theme'],
14+
1415
// builder: 'webpack',
1516
modules: [
1617
existsSync(resolve(__dirname, '../dist/module.mjs')) ? '@nuxtjs/tailwindcss' : '../src/module',
1718
'@nuxt/content',
1819
],
20+
1921
tailwindcss: {
2022
// viewer: false,
2123
config: {},
2224
exposeConfig: true,
2325
cssPath: '~/assets/css/tailwind.css',
2426
editorSupport: true,
2527
} satisfies Partial<ModuleOptions>,
28+
2629
hooks: {
2730
'tailwindcss:loadConfig': (config, configPath, idx) => {
2831
logger.info('Running `tailwindcss:loadConfig` hook...', Object.keys(config || {}), { configPath, idx })
@@ -54,9 +57,11 @@ export default defineNuxtConfig({
5457
logger.info('Running `tailwindcss:resolvedConfig` hook...', { typography: Boolean(config.theme.typography), hasOld: Boolean(oldConfig) })
5558
},
5659
} satisfies Partial<ModuleHooks>,
60+
5761
content: {
5862
documentDriven: true,
5963
},
64+
6065
css: [
6166
// Including Inter CSS is the first component to reproduce HMR issue. It also causes playground to look better,
6267
// since Inter is a native font for Tailwind UI
@@ -65,4 +70,6 @@ export default defineNuxtConfig({
6570
'@fontsource/inter/600.css',
6671
'@fontsource/inter/700.css',
6772
],
68-
})
73+
74+
compatibilityDate: '2024-07-11',
75+
})

pnpm-lock.yaml

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

src/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
147147
).then(configs => configs.reduce(
148148
(prev, curr) => configMerger(curr, prev),
149149
// internal default tailwind config
150-
configMerger(moduleOptions.config, { content: contentPaths }),
150+
configMerger(moduleOptions.config, { content: { files: contentPaths } }),
151151
)) as TWConfig
152152

153153
// Allow extending tailwindcss config by other modules
@@ -180,7 +180,7 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
180180
`\nconst inlineConfig = ${serializeConfig(moduleOptions.config as Partial<TWConfig>)};\n`,
181181
'const config = [',
182182
layerConfigs.join(',\n'),
183-
`].reduce((prev, curr) => configMerger(curr, prev), configMerger(inlineConfig, { content: ${JSON.stringify(contentPaths)} }));\n`,
183+
`].reduce((prev, curr) => configMerger(curr, prev), configMerger(inlineConfig, { content: { files: ${JSON.stringify(contentPaths)} } }));\n`,
184184
`module.exports = ${configUpdatedHook['main-config'] ? `(() => {const cfg=config;${configUpdatedHook['main-config']};return cfg;})()` : 'config'}\n`,
185185
].join('\n')
186186
},

src/runtime/merger.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** @typedef {import('tailwindcss').Config} TWConfig */
22

33
import { createDefu } from 'defu'
4+
import { klona } from 'klona'
45

56
const isJSObject = value => typeof value === 'object' && !Array.isArray(value)
67

@@ -12,7 +13,7 @@ const isJSObject = value => typeof value === 'object' && !Array.isArray(value)
1213
* @type {(...p: Array<Partial<TWConfig> | Record<string | number | symbol, any> | undefined>) => Partial<TWConfig>}
1314
*/
1415
export default (_base, ...defaults) => {
15-
const base = _base ?? Object.assign({}, defaults[0])
16+
const base = _base ?? klona(defaults[0])
1617

1718
return createDefu((obj, key, value) => {
1819
if (key === 'content') {

0 commit comments

Comments
 (0)