Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extends support #499

Merged
merged 16 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/content/2.tailwind/1.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ You can learn more about the [Tailwind configuration](https://tailwindcss.com/do
## Overwriting the configuration

You can extend the default configuration:

- with a [tailwind.config.js](#tailwindconfigjs) file
- using the [config option](#config-option)
- with the `tailwindcss:config` Nuxt hook
Expand Down Expand Up @@ -89,7 +90,6 @@ This config has less priority over the [tailwind.config.js](#tailwindconfigjs) f

::


### `tailwindcss:config` hook

::alert{type="warning"}
Expand Down Expand Up @@ -188,7 +188,6 @@ module.exports = {
}
```


## Referencing in the application

It can often be useful to reference Tailwind configuration values at runtime, e.g. to access some of your theme values when dynamically applying inline styles in a component.
Expand Down
16 changes: 16 additions & 0 deletions docs/content/3.examples/6.content.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: '@nuxt/content'
description: 'Discover how powerful it is to use TailwindCSS in @nuxt/content Markdown files!'
---

The module supports [@nuxt/content](https://content.nuxtjs.org), meaning you can use Tailwind classes inside your content files with MDC syntax!

```md
Hello, this is a [Markdown]{.px-1 .bg-blue-200 .rounded-lg} file!

::div{.w-full .bg-green-200 .p-4}
Another way to use it!
::
```

Learn more about the [Span Syntax](https://content.nuxtjs.org/guide/writing/mdc#span-text) and how to use classes in Markdown files!
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"codecov": "latest",
"eslint": "latest",
"nuxt": "npm:nuxt3@latest",
"@nuxt/content": "npm:@nuxt/content-edge@latest",
"standard-version": "latest"
}
}
13 changes: 13 additions & 0 deletions playground/content/content-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
::div{.my-4}
[@nuxt/content support]{.px-4 .text-xl .font-bold}
::

---

::div{.my-4 .px-4}
Hello World! :wave:

This is an integration test with [@nuxt/content](https://content.nuxtjs.org){.font-bold .hover:text-blue-500}! :smile:

It feels pretty smooth!
::
10 changes: 7 additions & 3 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { defineNuxtConfig } from 'nuxt'
import tailwindModule from '..'
import tailwindModule from '../src/module'

export default defineNuxtConfig({
buildModules: [
tailwindModule
modules: [
tailwindModule,
'@nuxt/content'
],
tailwindcss: {
exposeConfig: true
},
content: {
documentDriven: true
},
css: [
// Including Inter CSS is the first component to reproduce HMR issue. It also causes playground to look better,
// since Inter is a native font for Tailwind UI
Expand Down
4 changes: 2 additions & 2 deletions src/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { isAbsolute, resolve } from 'path'
import { HmrContext, Plugin } from 'vite'
import minimatch from 'minimatch'

export default function (tailwindConfig, rootDir: string, cssPath: string): Plugin {
const resolvedContent: string[] = tailwindConfig.content.map(f => !isAbsolute(f) ? resolve(rootDir, f) : f)
export default function (tailwindConfig: any = {}, rootDir: string, cssPath: string): Plugin {
const resolvedContent: string[] = (tailwindConfig.content || []).map(f => !isAbsolute(f) ? resolve(rootDir, f) : f)

return {
name: 'nuxt:tailwindcss',
Expand Down
13 changes: 11 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export default defineNuxtModule({
viewer: true,
exposeConfig: false,
injectPosition: 0,
disableHmrHotfix: false
disableHmrHotfix: false,
disableContentSupport: false
}),
async setup (moduleOptions, nuxt) {
const configPath = await resolvePath(moduleOptions.configPath)
Expand Down Expand Up @@ -100,7 +101,9 @@ export default defineNuxtModule({

// Allow extending tailwindcss config by other modules
// @ts-ignore
await nuxt.callHook('tailwindcss:config', tailwindConfig)
const _tailwindConfig = await nuxt.callHook('tailwindcss:config', tailwindConfig)
Tahul marked this conversation as resolved.
Show resolved Hide resolved
// Overwrite if returned
if (_tailwindConfig) { tailwindConfig = _tailwindConfig }

// Compute tailwindConfig hash
tailwindConfig._hash = String(Date.now())
Expand All @@ -120,6 +123,12 @@ export default defineNuxtModule({
await installModule('@nuxt/postcss8')
}

// Add support for @nuxt/content if module is present
if (!moduleOptions.disableContentSupport && (nuxt.options.modules.includes('@nuxt/content') || nuxt.options.modules.includes('@nuxt/content-edge'))) {
tailwindConfig.content = tailwindConfig.content ?? []
tailwindConfig.content.push(`${nuxt.options.buildDir}/cache/content/parsed/**/*.md`)
Tahul marked this conversation as resolved.
Show resolved Hide resolved
}

if (nuxt.options.dev && !moduleOptions.disableHmrHotfix) {
// Insert Vite plugin to work around HMR issue
addVitePlugin(vitePlugin(tailwindConfig, nuxt.options.rootDir, resolvedCss))
Expand Down
Loading