Skip to content

Commit

Permalink
chore(exposeConfig): provide write option for workaround, resolves #794
Browse files Browse the repository at this point in the history
  • Loading branch information
ineshbose committed Jan 18, 2024
1 parent d8e36e9 commit 4396ef0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 72 deletions.
2 changes: 1 addition & 1 deletion nuxt2-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"nuxt": "2.17.3",
"vue": "2.7.15",
"vue": "2.7.16",
"vue-router": "3.6.5"
},
"keywords": []
Expand Down
93 changes: 26 additions & 67 deletions nuxt2-playground/pnpm-lock.yaml

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

9 changes: 6 additions & 3 deletions src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ export default function createTemplates (resolvedConfig: Partial<TWConfig> | Res

addTemplate({
filename: `tailwind.config/${subpath}.mjs`,
getContents: () => `${validKeys.map(i => `const _${i} = ${JSON.stringify(value[i])}`).join('\n')}\nconst config = { ${validKeys.map(i => `"${i}": _${i}, `).join('')}${invalidKeys.map(i => `"${i}": ${JSON.stringify(value[i])}, `).join('')} }\nexport { config as default${validKeys.length > 0 ? ', _' : ''}${validKeys.join(', _')} }`
getContents: () => `${validKeys.map(i => `const _${i} = ${JSON.stringify(value[i])}`).join('\n')}\nconst config = { ${validKeys.map(i => `"${i}": _${i}, `).join('')}${invalidKeys.map(i => `"${i}": ${JSON.stringify(value[i])}, `).join('')} }\nexport { config as default${validKeys.length > 0 ? ', _' : ''}${validKeys.join(', _')} }`,
write: config.write
})
dtsContent.push(`declare module "${config.alias}/${subpath}" { ${validKeys.map(i => `export const _${i}: ${JSON.stringify(value[i])};`).join('')} const defaultExport: { ${validKeys.map(i => `"${i}": typeof _${i}, `).join('')}${invalidKeys.map(i => `"${i}": ${JSON.stringify(value[i])}, `).join('')} }; export default defaultExport; }`)
} else {
addTemplate({
filename: `tailwind.config/${subpath}.mjs`,
getContents: () => `export default ${JSON.stringify(value, null, 2)}`
getContents: () => `export default ${JSON.stringify(value, null, 2)}`,
write: config.write
})
dtsContent.push(`declare module "${config.alias}/${subpath}" { const defaultExport: ${JSON.stringify(value)}; export default defaultExport; }`)
}
Expand All @@ -45,7 +47,8 @@ export default function createTemplates (resolvedConfig: Partial<TWConfig> | Res
const values = Object.keys(value)
addTemplate({
filename: `tailwind.config/${subpath}.mjs`,
getContents: () => `${values.map(v => `import _${v} from "./${key}/${v}.mjs"`).join('\n')}\nconst config = { ${values.map(k => `"${k}": _${k}`).join(', ')} }\nexport { config as default${values.length > 0 ? ', _' : ''}${values.join(', _')} }`
getContents: () => `${values.map(v => `import _${v} from "./${key}/${v}.mjs"`).join('\n')}\nconst config = { ${values.map(k => `"${k}": _${k}`).join(', ')} }\nexport { config as default${values.length > 0 ? ', _' : ''}${values.join(', _')} }`,
write: config.write
})
dtsContent.push(`declare module "${config.alias}/${subpath}" {${Object.keys(value).map(v => ` export const _${v}: typeof import("${config.alias}/${join(`${key}/${subpath}`, `../${v}`)}")["default"];`).join('')} const defaultExport: { ${values.map(k => `"${k}": typeof _${k}`).join(', ')} }; export default defaultExport; }`)
}
Expand Down
6 changes: 5 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export type ExposeConfig = {
*
* @default 2
*/
level: number
level: number;
/**
* To write the templates to file-system for usage with code that does not have access to the Virtual File System. This applies only for Nuxt 3 with Vite.
*/
write?: boolean;
};

export type EditorSupportConfig = {
Expand Down

0 comments on commit 4396ef0

Please sign in to comment.