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

fix: add prefix for tailwind viewer route #460

Merged
merged 9 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test": "yarn lint"
},
"dependencies": {
"@nuxt/kit": "^3.0.0-rc.3",
"@nuxt/kit": "^3.0.0-rc.4",
"@nuxt/postcss8": "^1.1.3",
"@types/tailwindcss": "^3.0.10",
"autoprefixer": "^10.4.7",
Expand All @@ -36,7 +36,7 @@
"postcss": "^8.4.14",
"postcss-custom-properties": "^12.1.7",
"postcss-nesting": "^10.1.7",
"tailwind-config-viewer": "^1.7.0",
"tailwind-config-viewer": "^1.7.1",
"tailwindcss": "^3.0.24",
"ufo": "^0.8.4"
},
Expand All @@ -46,7 +46,7 @@
"@nuxtjs/eslint-config-typescript": "latest",
"codecov": "latest",
"eslint": "latest",
"nuxt": "^3.0.0-rc.3",
"nuxt": "^3.0.0-rc.4",
"standard-version": "latest"
}
}
13 changes: 6 additions & 7 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { join, relative } from 'path'
import { existsSync } from 'fs'
import { defuArrayFn } from 'defu'
import chalk from 'chalk'
import { withTrailingSlash } from 'ufo'
import consola from 'consola'
import {
defineNuxtModule,
Expand Down Expand Up @@ -114,21 +113,21 @@ export default defineNuxtModule({

// Add _tailwind config viewer endpoint
if (nuxt.options.dev && moduleOptions.viewer) {
const route = '/_tailwind/'
const route = '/_tailwind'
const createServer = await import('tailwind-config-viewer/server/index.js').then(r => r.default || r) as any
const { withoutTrailingSlash } = await import('ufo')
const _viewerDevMiddleware = createServer({ tailwindConfigProvider: () => tailwindConfig }).asMiddleware()
const { withTrailingSlash, withoutTrailingSlash } = await import('ufo')
const _viewerDevMiddleware = createServer({ tailwindConfigProvider: () => tailwindConfig, routerPrefix: route }).asMiddleware()
const viewerDevMiddleware = (req, res) => {
if (req.originalUrl === withoutTrailingSlash(route)) {
res.writeHead(301, { Location: withTrailingSlash(req.originalUrl) })
res.end()
return res.end()
}
_viewerDevMiddleware(req, res)
}
addDevServerHandler({ route, handler: viewerDevMiddleware })
nuxt.hook('listen', (_, listener) => {
const fullPath = `${withoutTrailingSlash(listener.url)}${route}`
logger.info(`Tailwind Viewer: ${chalk.underline.yellow(fullPath)}`)
const viewerUrl = `${withoutTrailingSlash(listener.url)}${route}`
logger.info(`Tailwind Viewer: ${chalk.underline.yellow(withTrailingSlash(viewerUrl))}`)
})
}
}
Expand Down
Loading