Skip to content

Commit 178e5ff

Browse files
committed
chore: commit more cases
1 parent c22006f commit 178e5ff

File tree

11 files changed

+1886
-7
lines changed

11 files changed

+1886
-7
lines changed

apps/nuxt-app/app.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
1313
target="_blank" rel="noopener noreferrer">
1414
By
15-
<img src="./assets/vercel.svg" alt="Vercel Logo" class="dark:invert" priority />
15+
<img width="200" src="./assets/vercel.svg" alt="Vercel Logo" class="dark:invert" priority />
1616
</a>
1717
</div>
1818
</div>
1919

2020
<div
2121
class="relative flex place-items-center before:absolute before:h-[300px] before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700/10 after:dark:from-sky-900 after:dark:via-[#0141ff]/40 before:lg:h-[360px]">
22-
<img class="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert" src="./assets/next.svg" alt="Next.js Logo"
22+
<img class="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert" width="300" src="./assets/next.svg" alt="Next.js Logo"
2323
priority />
2424
</div>
2525

apps/nuxt-app/nuxt.config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,14 @@ export default defineNuxtConfig({
88
autoprefixer: {}
99
}
1010
},
11-
modules: [nuxtPlugin]
11+
modules: [
12+
[
13+
nuxtPlugin,
14+
{
15+
classSetOutput: {
16+
type: 'all'
17+
}
18+
}
19+
]
20+
]
1221
})

apps/webpack5-vue3/vue.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const { webpackPlugin: utwm } = require('unplugin-tailwindcss-mangle')
33
module.exports = defineConfig({
44
transpileDependencies: true,
55
configureWebpack: (config) => {
6-
config.plugins.push(utwm())
6+
config.plugins.push(utwm({
7+
classSetOutput: true
8+
}))
79
}
810
})

packages/unplugin-tailwindcss-mangle/src/options.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
import type { Options } from './types'
1+
import type { Options, ClassSetOutputOptions } from './types'
22
import { getClassCacheSet } from 'tailwindcss-patch'
33
import ClassGenerator from './classGenerator'
44
import { createGlobMatcher } from './utils'
5+
import fs from 'fs'
6+
import path from 'path'
7+
import { pluginName } from './constants'
8+
9+
export function mkCacheDirectory(cwd = process.cwd()) {
10+
const cacheDirectory = path.resolve(cwd, 'node_modules', '.cache', pluginName)
11+
12+
const exists = fs.existsSync(cacheDirectory)
13+
if (!exists) {
14+
fs.mkdirSync(cacheDirectory, {
15+
recursive: true
16+
})
17+
}
18+
return cacheDirectory
19+
}
520

621
export function getOptions(options: Options | undefined = {}) {
722
const includeMatcher = createGlobMatcher(options.include, true)
@@ -18,15 +33,34 @@ export function getOptions(options: Options | undefined = {}) {
1833
return /[-:]/.test(className)
1934
}
2035
let classSet: Set<string>
36+
37+
const classSetOutputOptions: ClassSetOutputOptions = {
38+
filename: path.resolve(process.cwd(), 'node_modules', '.cache', pluginName, 'classSet.json'),
39+
type: 'partial'
40+
}
41+
if (typeof options.classSetOutput === 'object') {
42+
Object.assign(classSetOutputOptions, options.classSetOutput)
43+
}
44+
45+
function writeClassSetJson(set: Set<string>) {
46+
mkCacheDirectory()
47+
fs.writeFileSync(classSetOutputOptions.filename, JSON.stringify(Array.from(set), null, 2), 'utf-8')
48+
}
2149
// let cached: boolean
2250
const classGenerator = new ClassGenerator(options.classGenerator)
2351
function getCachedClassSet() {
2452
const set = getClassCacheSet()
53+
if (set.size && options.classSetOutput && classSetOutputOptions.type === 'all') {
54+
writeClassSetJson(set)
55+
}
2556
set.forEach((c) => {
2657
if (!isMangleClass(c)) {
2758
set.delete(c)
2859
}
2960
})
61+
if (set.size && options.classSetOutput && classSetOutputOptions.type === 'partial') {
62+
writeClassSetJson(set)
63+
}
3064

3165
classSet = set
3266

packages/unplugin-tailwindcss-mangle/src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ export interface IHandlerOptions {
2626
classGenerator: ClassGenerator
2727
}
2828

29+
export interface ClassSetOutputOptions {
30+
filename: string
31+
type: 'all' | 'partial'
32+
}
2933
export interface Options {
3034
classGenerator?: IClassGeneratorOptions
3135
exclude?: string[]
3236
include?: string[]
37+
classSetOutput?: boolean | ClassSetOutputOptions
3338
}

0 commit comments

Comments
 (0)