Skip to content

Commit

Permalink
feat: add util to write tw classes inside strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mitjans committed Nov 15, 2023
1 parent 58abedf commit 7d8a59e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
resolvePath,
addVitePlugin,
useNuxt,
addTemplate
addTemplate,
addImportsDir,
createResolver
} from '@nuxt/kit'

// @ts-expect-error
Expand Down Expand Up @@ -44,12 +46,14 @@ const defaults = (nuxt = useNuxt()): ModuleOptions => ({
exposeConfig: false,
exposeLevel: 2,
injectPosition: 'first',
disableHmrHotfix: false
disableHmrHotfix: false,
addTwUtil: false,
})

export default defineNuxtModule<ModuleOptions>({
meta: { name, version, configKey, compatibility }, defaults,
async setup (moduleOptions, nuxt) {
const { resolve } = createResolver(import.meta.url);
const [configPaths, contentPaths] = await resolveModulePaths(moduleOptions.configPath, nuxt)

const tailwindConfig = await Promise.all((
Expand Down Expand Up @@ -133,6 +137,11 @@ export default defineNuxtModule<ModuleOptions>({
}


if(moduleOptions.addTwUtil) {
addImportsDir(resolve('./runtime/utils'));
}


// enabled only in development
if (nuxt.options.dev) {
// Watch the Tailwind config file to restart the server
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/utils/tw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tw = function (tailwindClasses: TemplateStringsArray | string) {
return tailwindClasses
}
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,10 @@ export interface ModuleOptions {
* @default false
*/
disableHmrHotfix: boolean;
/**
* Add util to write Tailwind CSS classes inside strings with `` tw`{classes}` ``
*
* @default false
*/
addTwUtil: boolean;
}

0 comments on commit 7d8a59e

Please sign in to comment.