unplugin-tailwindcss-mangle 5.1.2 → 5.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,204 +0,0 @@
1
- import {
2
- getGroupedEntries,
3
- pluginName,
4
- posix
5
- } from "./chunk-TVEX3BIF.js";
6
- import {
7
- __dirname
8
- } from "./chunk-Q7X23R6B.js";
9
-
10
- // src/core/plugin.ts
11
- import { createUnplugin } from "unplugin";
12
-
13
- // src/core/factory.ts
14
- import { createFilter } from "@rollup/pluginutils";
15
- import { Context, cssHandler, htmlHandler, jsHandler, svelteHandler, vueHandler } from "@tailwindcss-mangle/core";
16
- import { isCSSRequest } from "is-css-request";
17
- var WEBPACK_LOADER = posix.resolve(__dirname, false ? "../../dist/loader.cjs" : "./loader.cjs");
18
- var JS_LIKE_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".cjs", ".mjs", ".ts", ".cts", ".mts", ".jsx", ".tsx"]);
19
- var HTML_LIKE_EXTENSIONS = /* @__PURE__ */ new Set([".html", ".htm"]);
20
- var CSS_LIKE_LANGS = /* @__PURE__ */ new Set(["css", "less", "sass", "scss", "styl", "stylus", "pcss", "postcss", "sss"]);
21
- var JS_LIKE_LANGS = /* @__PURE__ */ new Set(["js", "cjs", "mjs", "ts", "cts", "mts", "jsx", "tsx"]);
22
- var HTML_LIKE_LANGS = /* @__PURE__ */ new Set(["html", "htm"]);
23
- function normalizeLang(rawLang) {
24
- if (!rawLang) {
25
- return "";
26
- }
27
- return rawLang.toLowerCase().replace(/^\./, "");
28
- }
29
- function isLikelyMarkup(code) {
30
- return /<[a-z][\w:-]*(?:\s|>)/i.test(code);
31
- }
32
- function isHtmlFileRequest(id) {
33
- const cleanId = id.split("?")[0] ?? id;
34
- const ext = posix.extname(cleanId).toLowerCase();
35
- return HTML_LIKE_EXTENSIONS.has(ext);
36
- }
37
- function resolveTransformKind(id, code) {
38
- if (isCSSRequest(id)) {
39
- return "css";
40
- }
41
- const cleanId = id.split("?")[0] ?? id;
42
- const ext = posix.extname(cleanId).toLowerCase();
43
- const query = id.includes("?") ? id.slice(id.indexOf("?") + 1) : "";
44
- const params = new URLSearchParams(query);
45
- const type = params.get("type")?.toLowerCase();
46
- const lang = normalizeLang(params.get("lang"));
47
- if (type === "style") {
48
- return "css";
49
- }
50
- if (type === "script") {
51
- return "js";
52
- }
53
- if (type === "template") {
54
- if (lang && JS_LIKE_LANGS.has(lang)) {
55
- return "js";
56
- }
57
- if (lang && HTML_LIKE_LANGS.has(lang)) {
58
- return "html";
59
- }
60
- return isLikelyMarkup(code) ? "html" : "js";
61
- }
62
- if (lang) {
63
- if (CSS_LIKE_LANGS.has(lang)) {
64
- return "css";
65
- }
66
- if (JS_LIKE_LANGS.has(lang)) {
67
- return "js";
68
- }
69
- if (HTML_LIKE_LANGS.has(lang)) {
70
- return "html";
71
- }
72
- if (lang === "vue") {
73
- return "vue";
74
- }
75
- if (lang === "svelte") {
76
- return "svelte";
77
- }
78
- }
79
- if (ext === ".vue") {
80
- return "vue";
81
- }
82
- if (ext === ".svelte") {
83
- return "svelte";
84
- }
85
- if (HTML_LIKE_EXTENSIONS.has(ext)) {
86
- return "html";
87
- }
88
- if (JS_LIKE_EXTENSIONS.has(ext)) {
89
- return "js";
90
- }
91
- return isLikelyMarkup(code) ? "html" : "js";
92
- }
93
- var factory = (options) => {
94
- const ctx = new Context();
95
- let filter = createFilter(options?.sources?.include, options?.sources?.exclude);
96
- return [
97
- {
98
- name: `${pluginName}:pre`,
99
- enforce: "pre",
100
- async buildStart() {
101
- const initOptions = options === void 0 ? {} : { transformerOptions: options };
102
- await ctx.initConfig(initOptions);
103
- filter = createFilter(ctx.options.sources?.include, ctx.options.sources?.exclude);
104
- }
105
- },
106
- {
107
- name: `${pluginName}`,
108
- transformInclude(id) {
109
- const cleanId = id.split("?")[0] ?? id;
110
- if (isHtmlFileRequest(cleanId)) {
111
- return false;
112
- }
113
- return filter(cleanId);
114
- },
115
- async transform(code, id) {
116
- const opts = {
117
- ctx,
118
- id
119
- };
120
- const kind = resolveTransformKind(id, code);
121
- const framework = this.getNativeBuildContext?.().framework;
122
- if ((framework === "webpack" || framework === "rspack") && kind === "html" && isHtmlFileRequest(id)) {
123
- return null;
124
- }
125
- switch (kind) {
126
- case "css":
127
- return await cssHandler(code, opts);
128
- case "vue":
129
- return await vueHandler(code, opts);
130
- case "svelte":
131
- return await svelteHandler(code, opts);
132
- case "html":
133
- return htmlHandler(code, opts);
134
- case "js":
135
- default:
136
- return jsHandler(code, opts);
137
- }
138
- },
139
- webpack(compiler) {
140
- const { NormalModule } = compiler.webpack;
141
- compiler.hooks.compilation.tap(pluginName, (compilation) => {
142
- NormalModule.getCompilationHooks(compilation).loader.tap(pluginName, (_loaderContext, module) => {
143
- const idx = module.loaders.findIndex((x) => x.loader.includes("postcss-loader"));
144
- if (idx > -1) {
145
- module.loaders.splice(idx, 0, {
146
- loader: WEBPACK_LOADER,
147
- ident: null,
148
- options: {
149
- ctx
150
- },
151
- type: null
152
- });
153
- }
154
- });
155
- });
156
- }
157
- },
158
- {
159
- name: `${pluginName}:post`,
160
- enforce: "post",
161
- vite: {
162
- transformIndexHtml(html) {
163
- const { code } = htmlHandler(html, { ctx });
164
- return code;
165
- }
166
- },
167
- webpack(compiler) {
168
- const { Compilation, sources } = compiler.webpack;
169
- const { ConcatSource } = sources;
170
- compiler.hooks.compilation.tap(pluginName, (compilation) => {
171
- compilation.hooks.processAssets.tapPromise(
172
- {
173
- name: pluginName,
174
- stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
175
- },
176
- async (assets) => {
177
- const groupedEntries = getGroupedEntries(Object.entries(assets));
178
- for (const [id, cssSource] of groupedEntries.css) {
179
- const { code } = await cssHandler(cssSource.source().toString(), {
180
- id,
181
- ctx
182
- });
183
- const source = new ConcatSource(code);
184
- compilation.updateAsset(id, source);
185
- }
186
- }
187
- );
188
- });
189
- },
190
- writeBundle() {
191
- ctx.dump();
192
- }
193
- }
194
- ];
195
- };
196
- var factory_default = factory;
197
-
198
- // src/core/plugin.ts
199
- var unplugin = createUnplugin(factory_default);
200
- var plugin_default = unplugin;
201
-
202
- export {
203
- plugin_default
204
- };
@@ -1,10 +0,0 @@
1
- // ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.8_tsx@4.21.0_typescript@5.9.3_yaml@2.8.3/node_modules/tsup/assets/esm_shims.js
2
- import path from "path";
3
- import { fileURLToPath } from "url";
4
- var getFilename = () => fileURLToPath(import.meta.url);
5
- var getDirname = () => path.dirname(getFilename());
6
- var __dirname = /* @__PURE__ */ getDirname();
7
-
8
- export {
9
- __dirname
10
- };