generated from sonofmagic/monorepo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from sonofmagic/feature/add-vue-compiler
Feature/add vue compiler
- Loading branch information
Showing
33 changed files
with
1,049 additions
and
990 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"unplugin-tailwindcss-mangle": minor | ||
"@tailwindcss-mangle/core": minor | ||
"tailwindcss-patch": patch | ||
--- | ||
|
||
fix(tailwindcss-patch): monorepo basedir option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,32 @@ | |
"name": "@tailwindcss-mangle/config", | ||
"version": "2.2.2", | ||
"description": "The config and load function of tailwindcss-mangle", | ||
"author": "SonOfMagic <[email protected]>", | ||
"license": "MIT", | ||
"homepage": "https://github.com/sonofmagic/tailwindcss-mangle", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git" | ||
}, | ||
"keywords": [ | ||
"tailwindcss", | ||
"mangle", | ||
"patch", | ||
"core", | ||
"mangle", | ||
"shared", | ||
"utils" | ||
], | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"*": [ | ||
|
@@ -17,9 +36,6 @@ | |
] | ||
} | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
|
@@ -29,17 +45,6 @@ | |
"test": "vitest run --coverage.enabled", | ||
"test:dev": "vitest" | ||
}, | ||
"keywords": [ | ||
"tailwindcss", | ||
"mangle", | ||
"patch", | ||
"core", | ||
"mangle", | ||
"shared", | ||
"utils" | ||
], | ||
"author": "SonOfMagic <[email protected]>", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
|
@@ -48,10 +53,5 @@ | |
"@tailwindcss-mangle/shared": "workspace:^", | ||
"c12": "^1.11.1", | ||
"dedent": "^1.5.3" | ||
}, | ||
"homepage": "https://github.com/sonofmagic/tailwindcss-mangle", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,32 @@ | |
"name": "@tailwindcss-mangle/core", | ||
"version": "2.2.2", | ||
"description": "The core of tailwindcss-mangle", | ||
"author": "SonOfMagic <[email protected]>", | ||
"license": "MIT", | ||
"homepage": "https://github.com/sonofmagic/tailwindcss-mangle", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/sonofmagic/tailwindcss-mangle/issues" | ||
}, | ||
"keywords": [ | ||
"tailwindcss", | ||
"patch", | ||
"core", | ||
"mangle" | ||
], | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"*": [ | ||
|
@@ -17,9 +36,6 @@ | |
] | ||
} | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
|
@@ -30,51 +46,32 @@ | |
"test:dev": "vitest", | ||
"coverage": "vitest run --coverage" | ||
}, | ||
"keywords": [ | ||
"tailwindcss", | ||
"patch", | ||
"core", | ||
"mangle" | ||
], | ||
"author": "SonOfMagic <[email protected]>", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
"dependencies": { | ||
"@ast-core/escape": "^1.0.1", | ||
"@babel/core": "^7.24.7", | ||
"@babel/helper-plugin-utils": "^7.24.7", | ||
"@babel/parser": "^7.24.7", | ||
"@babel/preset-typescript": "^7.24.7", | ||
"@babel/traverse": "^7.24.7", | ||
"@babel/types": "^7.24.7", | ||
"@tailwindcss-mangle/config": "workspace:^", | ||
"@tailwindcss-mangle/shared": "workspace:^", | ||
"@vue/compiler-sfc": "^3.4.29", | ||
"fast-sort": "^3.4.0", | ||
"htmlparser2": "9.1.0", | ||
"magic-string": "^0.30.10", | ||
"micromatch": "^4.0.7", | ||
"parse5": "^7.1.2", | ||
"postcss": "^8.4.38", | ||
"postcss-selector-parser": "^6.1.0" | ||
}, | ||
"devDependencies": { | ||
"@parse5/tools": "^0.5.0", | ||
"@types/babel__core": "^7.20.5", | ||
"@types/babel__traverse": "^7.20.6", | ||
"@types/micromatch": "^4.0.7", | ||
"@vue/compiler-core": "^3.4.29", | ||
"@vue/compiler-sfc": "^3.4.27" | ||
}, | ||
"homepage": "https://github.com/sonofmagic/tailwindcss-mangle", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/sonofmagic/tailwindcss-mangle/issues" | ||
}, | ||
"directories": { | ||
"test": "test" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import _babelTraverse from '@babel/traverse' | ||
|
||
export { parse, parseExpression } from '@babel/parser' | ||
|
||
function _interopDefaultCompat(e: any) { | ||
return e && typeof e === 'object' && 'default' in e ? e.default : e | ||
} | ||
|
||
export const traverse = _interopDefaultCompat(_babelTraverse) as typeof _babelTraverse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
import process from 'node:process' | ||
|
||
export const isProd = () => process.env.NODE_ENV === 'production' | ||
export const isDev = () => process.env.NODE_ENV === 'development' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,38 @@ | ||
import { parse, serialize } from 'parse5' | ||
import { traverse } from '@parse5/tools' | ||
import { Parser } from 'htmlparser2' | ||
import MagicString from 'magic-string' | ||
import type { IHtmlHandlerOptions } from '../types' | ||
import { makeRegex, splitCode } from '../shared' | ||
// const { traverse } = await import('@parse5/tools') | ||
export function htmlHandler(rawSource: string, options: IHtmlHandlerOptions) { | ||
const { replaceMap, ctx } = options | ||
const fragment = parse(rawSource) | ||
traverse(fragment, { | ||
element(node) { | ||
const attribute = node.attrs.find(x => x.name === 'class') | ||
if (attribute) { | ||
const array = splitCode(attribute.value, { | ||
import { jsHandler } from '@/js' | ||
|
||
export function htmlHandler(raw: string | MagicString, options: IHtmlHandlerOptions) { | ||
const { ctx, isVue } = options | ||
const { replaceMap } = ctx | ||
const ms: MagicString = typeof raw === 'string' ? new MagicString(raw) : raw | ||
const parser = new Parser({ | ||
onattribute(name, value) { | ||
if (name === 'class') { | ||
const arr = splitCode(value, { | ||
splitQuote: false, | ||
}) | ||
for (const v of array) { | ||
let rawValue = value | ||
for (const v of arr) { | ||
if (replaceMap.has(v)) { | ||
attribute.value = attribute.value.replace(makeRegex(v), ctx.classGenerator.generateClassName(v).name) | ||
rawValue = rawValue.replace(makeRegex(v), ctx.classGenerator.generateClassName(v).name) | ||
} | ||
} | ||
ms.update(parser.startIndex + name.length + 2, parser.endIndex - 1, rawValue) | ||
} | ||
if (isVue) { | ||
if (name === ':class') { | ||
const { code } = jsHandler(value, { | ||
ctx, | ||
}) | ||
ms.update(parser.startIndex + name.length + 2, parser.endIndex - 1, code) | ||
} | ||
} | ||
}, | ||
}) | ||
return serialize(fragment) | ||
parser.write(ms.original) | ||
parser.end() | ||
return ms.toString() | ||
} |
Oops, something went wrong.