weapp-tailwindcss 5.0.0-next.3 → 5.0.0-next.5
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.
- package/README.md +4 -5
- package/bin/weapp-tailwindcss.js +1 -21
- package/dist/bundlers/shared/generator-css.d.ts +5 -2
- package/dist/bundlers/vite/generate-bundle.d.ts +1 -0
- package/dist/bundlers/vite/index.d.ts +1 -1
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +0 -1
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +1 -1
- package/dist/cli/context.d.ts +0 -3
- package/dist/cli/mount-options.d.ts +2 -0
- package/dist/cli.js +8 -2
- package/dist/cli.mjs +8 -2
- package/dist/constants.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro.d.ts +1 -0
- package/dist/defaults.js +5 -7
- package/dist/defaults.mjs +5 -7
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/options.d.ts +3 -4
- package/dist/{generator-mmhXzZnv.js → generator-9UEp8OoQ.js} +259 -21
- package/dist/{generator-Y-Ikv4Fu.mjs → generator-Dpp-5s8z.mjs} +260 -22
- package/dist/{generator-css-CRLrHW4F.js → generator-css-CGueCYbX.js} +173 -32
- package/dist/{generator-css-Bwy_Uz89.mjs → generator-css-MyjZhF0z.mjs} +173 -32
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/gulp.js +15 -11
- package/dist/gulp.mjs +15 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/index.d.ts +1 -0
- package/dist/js/literal-transform.d.ts +2 -0
- package/dist/{logger-BoVx1Dbt.mjs → logger-1gx9UllH.mjs} +21 -51
- package/dist/{logger-BZ45DZJT.js → logger-D9clu_3f.js} +21 -51
- package/dist/patcher-options-DnqazL9E.js +34 -0
- package/dist/patcher-options-GuOwX0-k.mjs +17 -0
- package/dist/postcss.d.ts +2 -2
- package/dist/postcss.js +37 -28
- package/dist/postcss.mjs +37 -28
- package/dist/presets.js +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/{recorder-XdFvVASS.mjs → recorder-BIW3Kuke.mjs} +5 -12
- package/dist/{recorder-GdTJ3QqX.js → recorder-D4BKt75Q.js} +5 -12
- package/dist/reset.d.ts +1 -0
- package/dist/{css-imports-BbrbluP9.js → run-tasks-Cq5A5nVD.js} +6 -55
- package/dist/{css-imports-CSdPq_Sc.mjs → run-tasks-DUVrDJGl.mjs} +5 -42
- package/dist/tailwindcss/miniprogram.d.ts +5 -1
- package/dist/tailwindcss/patcher-options.d.ts +3 -51
- package/dist/tailwindcss/patcher.d.ts +1 -2
- package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
- package/dist/tailwindcss/v4/patcher.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
- package/dist/tailwindcss/version.d.ts +4 -0
- package/dist/typedoc.export.d.ts +0 -2
- package/dist/types/index.d.ts +1 -3
- package/dist/types/shared.d.ts +3 -0
- package/dist/types/user-defined-options/general.d.ts +0 -2
- package/dist/types/user-defined-options/important.d.ts +3 -3
- package/dist/utils/disabled.d.ts +2 -3
- package/dist/version-CWBxRFPB.js +56 -0
- package/dist/version-WNz3MwRv.mjs +49 -0
- package/dist/{vite-DgRh_GXn.js → vite-BkMGwDeH.js} +106 -39
- package/dist/{vite-BDywuCjn.mjs → vite-fDM-UQpR.mjs} +89 -22
- package/dist/vite.d.ts +1 -2
- package/dist/vite.js +3 -4
- package/dist/vite.mjs +2 -2
- package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
- package/dist/{webpack-CAJR4hhP.js → webpack-CICGEKT9.js} +225 -43
- package/dist/{webpack-CiHqVZTg.mjs → webpack-D2Wdk28V.mjs} +214 -27
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +21 -30
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
- package/dist/experimental/index.d.ts +0 -2
- package/dist/experimental/oxc/ast-utils.d.ts +0 -30
- package/dist/experimental/oxc/index.d.ts +0 -2
- package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
- package/dist/experimental/shared/cache.d.ts +0 -3
- package/dist/experimental/shared/transform.d.ts +0 -3
- package/dist/experimental/shared.d.ts +0 -8
- package/dist/experimental/swc/ast-utils.d.ts +0 -30
- package/dist/experimental/swc/index.d.ts +0 -2
- package/dist/experimental/swc/module-specifiers.d.ts +0 -2
- package/dist/loader-anchors-1MumTAtA.mjs +0 -205
- package/dist/loader-anchors-TrFvT6g1.js +0 -273
- package/dist/patcher-options-6gJN2EXy.js +0 -115
- package/dist/patcher-options-DQfR5xxT.mjs +0 -92
- package/dist/types/disabled-options.d.ts +0 -4
- package/dist/webpack4.d.ts +0 -4
- package/dist/webpack4.js +0 -387
- package/dist/webpack4.mjs +0 -379
- package/scripts/postinstall.mjs +0 -59
|
@@ -9,13 +9,11 @@ export interface UserDefinedOptionsGeneralPart {
|
|
|
9
9
|
appType?: AppType;
|
|
10
10
|
arbitraryValues?: IArbitraryValues;
|
|
11
11
|
jsPreserveClass?: (keyword: string) => boolean | undefined;
|
|
12
|
-
staleClassNameFallback?: boolean;
|
|
13
12
|
jsArbitraryValueFallback?: boolean | 'auto';
|
|
14
13
|
replaceRuntimePackages?: boolean | Record<string, string>;
|
|
15
14
|
generator?: WeappTailwindcssGeneratorUserOptions;
|
|
16
15
|
disabledDefaultTemplateHandler?: boolean;
|
|
17
16
|
runtimeLoaderPath?: string;
|
|
18
|
-
runtimeCssImportRewriteLoaderPath?: string;
|
|
19
17
|
tailwindcssBasedir?: string;
|
|
20
18
|
cache?: boolean | ICreateCacheReturnType;
|
|
21
19
|
babelParserOptions?: ParserOptions & {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { CssCalcOptions, CssPreflightOptions, PresetEnvOptions, Px2rpxOptions, Rem2rpxOptions, UniAppXUnsupportedMode, UnitsToPxOptions, WeappAutoprefixerOptions } from '@weapp-tailwindcss/postcss/types';
|
|
2
2
|
import type { TailwindCssPatchOptions } from 'tailwindcss-patch';
|
|
3
|
-
import type { DisabledOptions } from '../disabled-options';
|
|
4
3
|
import type { ICustomAttributes } from '../shared';
|
|
5
4
|
export interface UniAppXComponentLocalStylesOptions {
|
|
6
5
|
enabled?: boolean;
|
|
@@ -12,7 +11,9 @@ export interface UniAppXOptions {
|
|
|
12
11
|
uvueUnsupported?: UniAppXUnsupportedMode;
|
|
13
12
|
}
|
|
14
13
|
export interface UserDefinedOptionsImportantPart {
|
|
15
|
-
disabled?: boolean |
|
|
14
|
+
disabled?: boolean | {
|
|
15
|
+
plugin?: boolean;
|
|
16
|
+
};
|
|
16
17
|
customAttributes?: ICustomAttributes;
|
|
17
18
|
customReplaceDictionary?: Record<string, string>;
|
|
18
19
|
ignoreTaggedTemplateExpressionIdentifiers?: (string | RegExp)[];
|
|
@@ -21,7 +22,6 @@ export interface UserDefinedOptionsImportantPart {
|
|
|
21
22
|
cssPreflightRange?: 'all';
|
|
22
23
|
cssCalc?: boolean | CssCalcOptions | (string | RegExp)[];
|
|
23
24
|
injectAdditionalCssVarScope?: boolean;
|
|
24
|
-
rewriteCssImports?: boolean;
|
|
25
25
|
cssSelectorReplacement?: {
|
|
26
26
|
root?: string | string[] | false;
|
|
27
27
|
universal?: string | string[] | false;
|
package/dist/utils/disabled.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { UserDefinedOptions } from '../types';
|
|
2
|
-
export interface
|
|
2
|
+
export interface ResolvedPluginDisabledState {
|
|
3
3
|
plugin: boolean;
|
|
4
|
-
rewriteCssImports: boolean;
|
|
5
4
|
}
|
|
6
|
-
export declare function
|
|
5
|
+
export declare function resolvePluginDisabledState(disabled: UserDefinedOptions['disabled']): ResolvedPluginDisabledState;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-8l464Juk.js");
|
|
2
|
+
let node_module = require("node:module");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
node_path = require_chunk.__toESM(node_path);
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
//#region src/tailwindcss/version.ts
|
|
7
|
+
function normalizeSupportedTailwindcssMajorVersion(version) {
|
|
8
|
+
return version === 3 || version === 4 ? version : void 0;
|
|
9
|
+
}
|
|
10
|
+
function readPackageJson(packageJsonPath) {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse((0, node_fs.readFileSync)(packageJsonPath, "utf8"));
|
|
13
|
+
} catch {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function findPackageJsonDeclaringPackage(packageName, base) {
|
|
18
|
+
let current = node_path.default.resolve(base);
|
|
19
|
+
while (true) {
|
|
20
|
+
const pkgPath = node_path.default.join(current, "package.json");
|
|
21
|
+
if ((0, node_fs.existsSync)(pkgPath)) {
|
|
22
|
+
const pkg = readPackageJson(pkgPath);
|
|
23
|
+
if (readDeclaredPackageVersion(packageName, pkg)) return pkgPath;
|
|
24
|
+
if (pkg?.name !== "weapp-tailwindcss") return;
|
|
25
|
+
}
|
|
26
|
+
const parent = node_path.default.dirname(current);
|
|
27
|
+
if (parent === current) return;
|
|
28
|
+
current = parent;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function readDeclaredPackageVersion(packageName, pkg) {
|
|
32
|
+
return pkg?.dependencies?.[packageName] ?? pkg?.devDependencies?.[packageName] ?? pkg?.peerDependencies?.[packageName] ?? pkg?.optionalDependencies?.[packageName];
|
|
33
|
+
}
|
|
34
|
+
function readDeclaredPackageMajorVersion(version) {
|
|
35
|
+
const match = version?.match(/(?:^|\D)([34])(?:\.|\b)/);
|
|
36
|
+
return normalizeSupportedTailwindcssMajorVersion(match ? Number(match[1]) : void 0);
|
|
37
|
+
}
|
|
38
|
+
function readInstalledPackageMajorVersion(packageName, base) {
|
|
39
|
+
const packageJsonPath = findPackageJsonDeclaringPackage(packageName, base);
|
|
40
|
+
if (!packageJsonPath) return;
|
|
41
|
+
const declaredVersion = readDeclaredPackageVersion(packageName, readPackageJson(packageJsonPath));
|
|
42
|
+
if (!declaredVersion) return;
|
|
43
|
+
try {
|
|
44
|
+
const pkg = (0, node_module.createRequire)(packageJsonPath)(`${packageName}/package.json`);
|
|
45
|
+
return normalizeSupportedTailwindcssMajorVersion(Number(pkg.version?.split(".")[0]));
|
|
46
|
+
} catch {
|
|
47
|
+
return readDeclaredPackageMajorVersion(declaredVersion);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
Object.defineProperty(exports, "readInstalledPackageMajorVersion", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function() {
|
|
54
|
+
return readInstalledPackageMajorVersion;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
//#region src/tailwindcss/version.ts
|
|
5
|
+
function normalizeSupportedTailwindcssMajorVersion(version) {
|
|
6
|
+
return version === 3 || version === 4 ? version : void 0;
|
|
7
|
+
}
|
|
8
|
+
function readPackageJson(packageJsonPath) {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
11
|
+
} catch {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function findPackageJsonDeclaringPackage(packageName, base) {
|
|
16
|
+
let current = path.resolve(base);
|
|
17
|
+
while (true) {
|
|
18
|
+
const pkgPath = path.join(current, "package.json");
|
|
19
|
+
if (existsSync(pkgPath)) {
|
|
20
|
+
const pkg = readPackageJson(pkgPath);
|
|
21
|
+
if (readDeclaredPackageVersion(packageName, pkg)) return pkgPath;
|
|
22
|
+
if (pkg?.name !== "weapp-tailwindcss") return;
|
|
23
|
+
}
|
|
24
|
+
const parent = path.dirname(current);
|
|
25
|
+
if (parent === current) return;
|
|
26
|
+
current = parent;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function readDeclaredPackageVersion(packageName, pkg) {
|
|
30
|
+
return pkg?.dependencies?.[packageName] ?? pkg?.devDependencies?.[packageName] ?? pkg?.peerDependencies?.[packageName] ?? pkg?.optionalDependencies?.[packageName];
|
|
31
|
+
}
|
|
32
|
+
function readDeclaredPackageMajorVersion(version) {
|
|
33
|
+
const match = version?.match(/(?:^|\D)([34])(?:\.|\b)/);
|
|
34
|
+
return normalizeSupportedTailwindcssMajorVersion(match ? Number(match[1]) : void 0);
|
|
35
|
+
}
|
|
36
|
+
function readInstalledPackageMajorVersion(packageName, base) {
|
|
37
|
+
const packageJsonPath = findPackageJsonDeclaringPackage(packageName, base);
|
|
38
|
+
if (!packageJsonPath) return;
|
|
39
|
+
const declaredVersion = readDeclaredPackageVersion(packageName, readPackageJson(packageJsonPath));
|
|
40
|
+
if (!declaredVersion) return;
|
|
41
|
+
try {
|
|
42
|
+
const pkg = createRequire(packageJsonPath)(`${packageName}/package.json`);
|
|
43
|
+
return normalizeSupportedTailwindcssMajorVersion(Number(pkg.version?.split(".")[0]));
|
|
44
|
+
} catch {
|
|
45
|
+
return readDeclaredPackageMajorVersion(declaredVersion);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { readInstalledPackageMajorVersion as t };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-8l464Juk.js");
|
|
2
|
-
const require_generator = require("./generator-
|
|
3
|
-
const require_patcher_options = require("./patcher-options-
|
|
4
|
-
const require_recorder = require("./recorder-
|
|
2
|
+
const require_generator = require("./generator-9UEp8OoQ.js");
|
|
3
|
+
const require_patcher_options = require("./patcher-options-DnqazL9E.js");
|
|
4
|
+
const require_recorder = require("./recorder-D4BKt75Q.js");
|
|
5
5
|
const require_utils = require("./utils-DmC9_In3.js");
|
|
6
|
-
const require_logger = require("./logger-
|
|
7
|
-
const require_generator_css = require("./generator-css-
|
|
8
|
-
const
|
|
6
|
+
const require_logger = require("./logger-D9clu_3f.js");
|
|
7
|
+
const require_generator_css = require("./generator-css-CGueCYbX.js");
|
|
8
|
+
const require_run_tasks = require("./run-tasks-Cq5A5nVD.js");
|
|
9
9
|
let node_path = require("node:path");
|
|
10
10
|
node_path = require_chunk.__toESM(node_path);
|
|
11
11
|
let node_process = require("node:process");
|
|
@@ -480,7 +480,7 @@ function createUniAppXPlugins(options) {
|
|
|
480
480
|
function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
481
481
|
return async () => {
|
|
482
482
|
const { cache, hashKey, createHandlerOptions, debug, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
|
|
483
|
-
const absoluteFile =
|
|
483
|
+
const absoluteFile = require_run_tasks.toAbsoluteOutputPath(file, outDir);
|
|
484
484
|
const rawSource = originalSource.source.toString();
|
|
485
485
|
await require_generator_css.processCachedTask({
|
|
486
486
|
cache,
|
|
@@ -512,6 +512,22 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
512
512
|
}
|
|
513
513
|
//#endregion
|
|
514
514
|
//#region src/bundlers/vite/css-finalizer.ts
|
|
515
|
+
function isAddWatchFileInvalidRollupPhaseError$1(error) {
|
|
516
|
+
const candidate = error;
|
|
517
|
+
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
518
|
+
}
|
|
519
|
+
function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
520
|
+
if (typeof ctx.addWatchFile !== "function") return;
|
|
521
|
+
for (const dependency of dependencies ?? []) try {
|
|
522
|
+
ctx.addWatchFile(dependency);
|
|
523
|
+
} catch (error) {
|
|
524
|
+
if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
|
|
525
|
+
_weapp_tailwindcss_logger.logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
throw error;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
515
531
|
function createCssHandlerOptions(opts, majorVersion, file) {
|
|
516
532
|
return {
|
|
517
533
|
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
@@ -524,7 +540,7 @@ function shouldGenerateCssByGenerator(opts, file, rawSource, processed) {
|
|
|
524
540
|
return processed && shouldFinalizeProcessedCssAsset(opts, file);
|
|
525
541
|
}
|
|
526
542
|
function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
527
|
-
return
|
|
543
|
+
return opts.mainCssChunkMatcher(file, opts.appType);
|
|
528
544
|
}
|
|
529
545
|
function createViteCssFinalizerOutputPlugin(context) {
|
|
530
546
|
return {
|
|
@@ -563,6 +579,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
563
579
|
}) : void 0;
|
|
564
580
|
const nextCss = generated?.css ?? (await opts.styleHandler(rawSource, cssHandlerOptions)).css;
|
|
565
581
|
if (generated) {
|
|
582
|
+
registerGeneratorDependencies$1(this, generated.dependencies);
|
|
566
583
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
567
584
|
recordCssAssetResult?.(file, nextCss);
|
|
568
585
|
if (cssHandlerOptions.isMainChunk) rememberMainCssSource?.(file, rawSource);
|
|
@@ -593,11 +610,11 @@ function isJavaScriptEntry(entry) {
|
|
|
593
610
|
}
|
|
594
611
|
function createBundleModuleGraphOptions(outputDir, entries) {
|
|
595
612
|
const normalizedEntries = /* @__PURE__ */ new Map();
|
|
596
|
-
for (const [id, entry] of entries) normalizedEntries.set(
|
|
597
|
-
const getEntry = (id) => entries.get(id) ?? normalizedEntries.get(
|
|
613
|
+
for (const [id, entry] of entries) normalizedEntries.set(require_run_tasks.normalizeOutputPathKey(id), entry);
|
|
614
|
+
const getEntry = (id) => entries.get(id) ?? normalizedEntries.get(require_run_tasks.normalizeOutputPathKey(id));
|
|
598
615
|
return {
|
|
599
616
|
resolve(specifier, importer) {
|
|
600
|
-
return
|
|
617
|
+
return require_run_tasks.resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => Boolean(getEntry(candidate)));
|
|
601
618
|
},
|
|
602
619
|
load(id) {
|
|
603
620
|
const entry = getEntry(id);
|
|
@@ -612,9 +629,9 @@ function createBundleModuleGraphOptions(outputDir, entries) {
|
|
|
612
629
|
function applyLinkedResults(linked, entries, onLinkedUpdate, onApplied) {
|
|
613
630
|
if (!linked) return;
|
|
614
631
|
const normalizedEntries = /* @__PURE__ */ new Map();
|
|
615
|
-
for (const [entryId, entry] of entries) normalizedEntries.set(
|
|
632
|
+
for (const [entryId, entry] of entries) normalizedEntries.set(require_run_tasks.normalizeOutputPathKey(entryId), entry);
|
|
616
633
|
for (const [id, { code }] of Object.entries(linked)) {
|
|
617
|
-
const entry = entries.get(id) ?? normalizedEntries.get(
|
|
634
|
+
const entry = entries.get(id) ?? normalizedEntries.get(require_run_tasks.normalizeOutputPathKey(id));
|
|
618
635
|
if (!entry) continue;
|
|
619
636
|
const previous = readOutputEntry(entry);
|
|
620
637
|
if (previous == null || previous === code) continue;
|
|
@@ -735,7 +752,7 @@ function collectJsEntries(fileName, output, outDir, store) {
|
|
|
735
752
|
output
|
|
736
753
|
};
|
|
737
754
|
if (!isJavaScriptEntry(entry)) return;
|
|
738
|
-
const absolute =
|
|
755
|
+
const absolute = require_run_tasks.toAbsoluteOutputPath(fileName, outDir);
|
|
739
756
|
store.set(absolute, entry);
|
|
740
757
|
}
|
|
741
758
|
function markProcessFile(type, file, processFiles) {
|
|
@@ -925,11 +942,11 @@ function hasPathDependentCssUrl(rawSource) {
|
|
|
925
942
|
return false;
|
|
926
943
|
}
|
|
927
944
|
function createCssTransformShareScope(file, rawSource) {
|
|
928
|
-
if (CSS_IMPORT_RE.test(rawSource) || hasPathDependentCssUrl(rawSource)) return `dir:${
|
|
945
|
+
if (CSS_IMPORT_RE.test(rawSource) || hasPathDependentCssUrl(rawSource)) return `dir:${require_run_tasks.normalizeOutputPathKey(node_path.default.dirname(file))}`;
|
|
929
946
|
return "global";
|
|
930
947
|
}
|
|
931
948
|
function createCssTransformShareScopeKey(opts, file, rawSource) {
|
|
932
|
-
if (
|
|
949
|
+
if (opts.mainCssChunkMatcher(file, opts.appType)) return `main:${require_run_tasks.normalizeOutputPathKey(file)}`;
|
|
933
950
|
return createCssTransformShareScope(file, rawSource);
|
|
934
951
|
}
|
|
935
952
|
function createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature) {
|
|
@@ -947,6 +964,22 @@ function createReplayCssAsset(fileName, source) {
|
|
|
947
964
|
originalFileNames: []
|
|
948
965
|
};
|
|
949
966
|
}
|
|
967
|
+
function isAddWatchFileInvalidRollupPhaseError(error) {
|
|
968
|
+
const candidate = error;
|
|
969
|
+
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
970
|
+
}
|
|
971
|
+
function registerGeneratorDependencies(ctx, dependencies) {
|
|
972
|
+
if (typeof ctx.addWatchFile !== "function") return;
|
|
973
|
+
for (const dependency of dependencies ?? []) try {
|
|
974
|
+
ctx.addWatchFile(dependency);
|
|
975
|
+
} catch (error) {
|
|
976
|
+
if (isAddWatchFileInvalidRollupPhaseError(error)) {
|
|
977
|
+
_weapp_tailwindcss_logger.logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
throw error;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
950
983
|
function hasOmittedKnownBundleFiles(currentBundleFiles, previousBundleFiles) {
|
|
951
984
|
const currentFileSet = new Set(currentBundleFiles);
|
|
952
985
|
for (const file of previousBundleFiles) if (!currentFileSet.has(file)) return true;
|
|
@@ -984,6 +1017,7 @@ function createGenerateBundleHook(context) {
|
|
|
984
1017
|
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
985
1018
|
const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
986
1019
|
return async function generateBundle(_opt, bundle) {
|
|
1020
|
+
const addWatchFile = (id) => this.addWatchFile?.(id);
|
|
987
1021
|
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, recordCssAssetResult, getSourceCandidates, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSources, getRememberedMainCssSignature, setRememberedMainCssSignature, recordGeneratorCandidates } = context;
|
|
988
1022
|
const { appType, cache, mainCssChunkMatcher, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
|
|
989
1023
|
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
@@ -1035,15 +1069,15 @@ function createGenerateBundleHook(context) {
|
|
|
1035
1069
|
} else debug("build mode full process html=%d[%s] js=%d[%s] css=%d[%s]", processFiles.html.size, formatDebugFileList(processFiles.html), processFiles.js.size, formatDebugFileList(processFiles.js), processFiles.css.size, formatDebugFileList(processFiles.css));
|
|
1036
1070
|
const jsEntries = snapshot.jsEntries;
|
|
1037
1071
|
const normalizedJsEntries = /* @__PURE__ */ new Map();
|
|
1038
|
-
for (const [id, entry] of jsEntries) normalizedJsEntries.set(
|
|
1039
|
-
const getJsEntry = (id) => jsEntries.get(id) ?? normalizedJsEntries.get(
|
|
1072
|
+
for (const [id, entry] of jsEntries) normalizedJsEntries.set(require_run_tasks.normalizeOutputPathKey(id), entry);
|
|
1073
|
+
const getJsEntry = (id) => jsEntries.get(id) ?? normalizedJsEntries.get(require_run_tasks.normalizeOutputPathKey(id));
|
|
1040
1074
|
const moduleGraphOptions = createBundleModuleGraphOptions(outDir, jsEntries);
|
|
1041
1075
|
const runtimeStart = performance.now();
|
|
1042
1076
|
const runtime = useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv) : await context.ensureRuntimeClassSet(forceRuntimeRefreshByEnv);
|
|
1043
1077
|
const shouldFilterTailwindV4MiniProgramCandidates = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp";
|
|
1044
1078
|
await waitForSourceCandidateSyncs?.();
|
|
1045
1079
|
const sourceCandidates = getSourceCandidates?.() ?? /* @__PURE__ */ new Set();
|
|
1046
|
-
const collectedGeneratorCandidates =
|
|
1080
|
+
const collectedGeneratorCandidates = new Set(sourceCandidates);
|
|
1047
1081
|
const generatorRuntime = collectLegacyContainerCompatCandidates(sourceCandidates, shouldFilterTailwindV4MiniProgramCandidates ? require_generator.filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates);
|
|
1048
1082
|
const generatorCandidateSignature = createCandidateSignature(generatorRuntime);
|
|
1049
1083
|
recordGeneratorCandidates?.(generatorRuntime);
|
|
@@ -1165,6 +1199,7 @@ function createGenerateBundleHook(context) {
|
|
|
1165
1199
|
debug
|
|
1166
1200
|
});
|
|
1167
1201
|
if (generated) {
|
|
1202
|
+
registerGeneratorDependencies({ addWatchFile }, generated.dependencies);
|
|
1168
1203
|
if (debugCssDiff) debug("css diff %s: %s", file, summarizeStringDiff(rawSource, generated.css));
|
|
1169
1204
|
debug("css generated result: %s bytes=%d", file, generated.css.length);
|
|
1170
1205
|
recordCssAssetResult?.(file, generated.css);
|
|
@@ -1288,7 +1323,7 @@ function createGenerateBundleHook(context) {
|
|
|
1288
1323
|
}
|
|
1289
1324
|
}
|
|
1290
1325
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature);
|
|
1291
|
-
if (useIncrementalMode
|
|
1326
|
+
if (useIncrementalMode) for (const [file, rawSource] of getRememberedMainCssSources?.() ?? []) {
|
|
1292
1327
|
if (bundleFiles.includes(file) || getRememberedMainCssSignature?.(file) === cssRuntimeSignature) continue;
|
|
1293
1328
|
tasks.push((async () => {
|
|
1294
1329
|
const start = performance.now();
|
|
@@ -1307,6 +1342,7 @@ function createGenerateBundleHook(context) {
|
|
|
1307
1342
|
const css = generated?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css;
|
|
1308
1343
|
setRememberedMainCssSignature?.(file, cssRuntimeSignature);
|
|
1309
1344
|
if (generated) {
|
|
1345
|
+
registerGeneratorDependencies({ addWatchFile }, generated.dependencies);
|
|
1310
1346
|
recordCssAssetResult?.(file, generated.css);
|
|
1311
1347
|
debug("css replay generated result: %s bytes=%d", file, css.length);
|
|
1312
1348
|
}
|
|
@@ -1324,7 +1360,7 @@ function createGenerateBundleHook(context) {
|
|
|
1324
1360
|
debug("css replay handle: %s", file);
|
|
1325
1361
|
})());
|
|
1326
1362
|
}
|
|
1327
|
-
|
|
1363
|
+
require_run_tasks.pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
1328
1364
|
await Promise.all(tasks);
|
|
1329
1365
|
for (const apply of pendingLinkedUpdates) apply();
|
|
1330
1366
|
updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
@@ -1559,6 +1595,34 @@ function resolveImplicitAppTypeFromViteRoot(root) {
|
|
|
1559
1595
|
}
|
|
1560
1596
|
}
|
|
1561
1597
|
//#endregion
|
|
1598
|
+
//#region src/bundlers/shared/css-imports.ts
|
|
1599
|
+
const tailwindcssImportRE = /^tailwindcss(?:\/.*)?$/;
|
|
1600
|
+
const tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])(tailwindcss(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
|
|
1601
|
+
function normalizeTailwindcssSpecifier(specifier) {
|
|
1602
|
+
if (specifier === "tailwindcss$") return "tailwindcss";
|
|
1603
|
+
return specifier;
|
|
1604
|
+
}
|
|
1605
|
+
function getTailwindcssSubpath(specifier) {
|
|
1606
|
+
if (specifier === "tailwindcss") return "index.css";
|
|
1607
|
+
return specifier.slice(12);
|
|
1608
|
+
}
|
|
1609
|
+
function resolveTailwindcssImport(specifier, pkgDir, options) {
|
|
1610
|
+
const normalized = normalizeTailwindcssSpecifier(specifier);
|
|
1611
|
+
if (!tailwindcssImportRE.test(normalized)) return null;
|
|
1612
|
+
if (normalized === "tailwindcss") return options?.rootImport ?? "weapp-tailwindcss/index.css";
|
|
1613
|
+
return (options?.join ?? node_path.default.join)(pkgDir, getTailwindcssSubpath(normalized));
|
|
1614
|
+
}
|
|
1615
|
+
function rewriteTailwindcssImportsInCode(code, pkgDir, options) {
|
|
1616
|
+
let hasReplacements = false;
|
|
1617
|
+
const rewritten = code.replace(tailwindcssCssImportStatementRE, (full, prefix, quote, specifier, suffix) => {
|
|
1618
|
+
const replacement = resolveTailwindcssImport(specifier, pkgDir, options);
|
|
1619
|
+
if (!replacement) return full;
|
|
1620
|
+
hasReplacements = true;
|
|
1621
|
+
return `${prefix}${quote}${replacement}${suffix}`;
|
|
1622
|
+
});
|
|
1623
|
+
return hasReplacements ? rewritten : void 0;
|
|
1624
|
+
}
|
|
1625
|
+
//#endregion
|
|
1562
1626
|
//#region src/bundlers/vite/rewrite-css-imports.ts
|
|
1563
1627
|
function joinPosixPath(base, subpath) {
|
|
1564
1628
|
if (base.endsWith("/")) return `${base}${subpath}`;
|
|
@@ -1569,9 +1633,12 @@ function isCssLikeImporter(importer) {
|
|
|
1569
1633
|
const normalized = (0, _weapp_tailwindcss_shared.cleanUrl)(importer);
|
|
1570
1634
|
return isCSSRequest(normalized) || normalized.endsWith("/*");
|
|
1571
1635
|
}
|
|
1636
|
+
function stripTailwindConfigDirectives(code) {
|
|
1637
|
+
return code.replace(/^\s*@config\s+(?:"[^"]+"|'[^']+')[^;\n]*;\s*$/gm, "");
|
|
1638
|
+
}
|
|
1572
1639
|
function createRewriteCssImportsPlugins(options) {
|
|
1573
1640
|
if (!options.shouldRewrite) return [];
|
|
1574
|
-
const { appType, getAppType, rootImport, weappTailwindcssDirPosix } = options;
|
|
1641
|
+
const { appType, getAppType, rootImport, shouldOwnTailwindGeneration, weappTailwindcssDirPosix } = options;
|
|
1575
1642
|
const resolveAppType = () => getAppType?.() ?? appType;
|
|
1576
1643
|
return [{
|
|
1577
1644
|
name: `${require_recorder.vitePluginName}:rewrite-css-imports`,
|
|
@@ -1579,7 +1646,7 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
1579
1646
|
resolveId: {
|
|
1580
1647
|
order: "pre",
|
|
1581
1648
|
handler(id, importer) {
|
|
1582
|
-
const replacement =
|
|
1649
|
+
const replacement = resolveTailwindcssImport(id, weappTailwindcssDirPosix, {
|
|
1583
1650
|
join: joinPosixPath,
|
|
1584
1651
|
appType: resolveAppType(),
|
|
1585
1652
|
rootImport
|
|
@@ -1593,14 +1660,15 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
1593
1660
|
order: "pre",
|
|
1594
1661
|
handler(code, id) {
|
|
1595
1662
|
if (!isCSSRequest(id)) return null;
|
|
1596
|
-
const rewritten =
|
|
1663
|
+
const rewritten = rewriteTailwindcssImportsInCode(code, weappTailwindcssDirPosix, {
|
|
1597
1664
|
join: joinPosixPath,
|
|
1598
1665
|
appType: resolveAppType(),
|
|
1599
1666
|
rootImport
|
|
1600
1667
|
});
|
|
1601
|
-
|
|
1668
|
+
const nextCode = shouldOwnTailwindGeneration ? stripTailwindConfigDirectives(rewritten ?? code) : rewritten;
|
|
1669
|
+
if (!nextCode || nextCode === code) return null;
|
|
1602
1670
|
return {
|
|
1603
|
-
code:
|
|
1671
|
+
code: nextCode,
|
|
1604
1672
|
map: null
|
|
1605
1673
|
};
|
|
1606
1674
|
}
|
|
@@ -1762,7 +1830,7 @@ function createSourceCandidateCollector() {
|
|
|
1762
1830
|
//#endregion
|
|
1763
1831
|
//#region src/bundlers/vite/index.ts
|
|
1764
1832
|
const debug = require_recorder.createDebug();
|
|
1765
|
-
const weappTailwindcssPackageDir =
|
|
1833
|
+
const weappTailwindcssPackageDir = require_run_tasks.resolvePackageDir("weapp-tailwindcss");
|
|
1766
1834
|
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
1767
1835
|
const PACKAGE_JSON_FILE = "package.json";
|
|
1768
1836
|
const tailwindPostcssPluginNames = new Set(["tailwindcss", "@tailwindcss/postcss"]);
|
|
@@ -1864,24 +1932,24 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
1864
1932
|
return resolvedRoot;
|
|
1865
1933
|
}
|
|
1866
1934
|
/**
|
|
1867
|
-
* @name
|
|
1935
|
+
* @name WeappTailwindcss
|
|
1868
1936
|
* @description uni-app vite / uni-app-x 版本插件
|
|
1869
1937
|
* @link https://tw.icebreaker.top/docs/quick-start/frameworks/uni-app-vite
|
|
1870
1938
|
*/
|
|
1871
|
-
function
|
|
1939
|
+
function WeappTailwindcss(options = {}) {
|
|
1872
1940
|
const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
1873
|
-
const rewriteCssImportsSpecified = Object.hasOwn(options, "rewriteCssImports");
|
|
1874
1941
|
const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
1875
1942
|
const opts = require_recorder.getCompilerContext(options);
|
|
1876
1943
|
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, twPatcher: initialTwPatcher, refreshTailwindcssPatcher, uniAppX, disabledDefaultTemplateHandler } = opts;
|
|
1877
1944
|
const uniAppXEnabled = require_logger.isUniAppXEnabled(uniAppX);
|
|
1878
|
-
const disabledOptions =
|
|
1945
|
+
const disabledOptions = require_run_tasks.resolvePluginDisabledState(disabled);
|
|
1879
1946
|
const tailwindcssMajorVersion = initialTwPatcher.majorVersion ?? 0;
|
|
1880
|
-
const shouldOwnTailwindGeneration =
|
|
1881
|
-
const shouldRewriteCssImports =
|
|
1947
|
+
const shouldOwnTailwindGeneration = !disabledOptions.plugin;
|
|
1948
|
+
const shouldRewriteCssImports = tailwindcssMajorVersion >= 4;
|
|
1882
1949
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
1883
1950
|
getAppType: () => opts.appType,
|
|
1884
1951
|
rootImport: shouldOwnTailwindGeneration ? `${weappTailwindcssDirPosix}/generator-placeholder.css` : void 0,
|
|
1952
|
+
shouldOwnTailwindGeneration,
|
|
1885
1953
|
shouldRewrite: shouldRewriteCssImports,
|
|
1886
1954
|
weappTailwindcssDirPosix
|
|
1887
1955
|
});
|
|
@@ -1918,8 +1986,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1918
1986
|
uniAppX: uniAppXEnabled,
|
|
1919
1987
|
customAttributesEntities,
|
|
1920
1988
|
disabledDefaultTemplateHandler,
|
|
1921
|
-
configPath
|
|
1922
|
-
rewriteCssImports: shouldRewriteCssImports
|
|
1989
|
+
configPath
|
|
1923
1990
|
});
|
|
1924
1991
|
const changed = signature !== runtimeRefreshSignature || optionsKey !== runtimeRefreshOptionsKey;
|
|
1925
1992
|
runtimeRefreshSignature = signature;
|
|
@@ -2001,10 +2068,10 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
2001
2068
|
const getResolvedConfig = () => resolvedConfig;
|
|
2002
2069
|
const markCssAssetProcessed = (asset, file) => {
|
|
2003
2070
|
processedCssAssets.add(asset);
|
|
2004
|
-
if (file) processedCssAssetFiles.add(
|
|
2071
|
+
if (file) processedCssAssetFiles.add(require_run_tasks.normalizeOutputPathKey(file));
|
|
2005
2072
|
};
|
|
2006
2073
|
const isCssAssetProcessed = (asset, file) => {
|
|
2007
|
-
return processedCssAssets.has(asset) || (file ? processedCssAssetFiles.has(
|
|
2074
|
+
return processedCssAssets.has(asset) || (file ? processedCssAssetFiles.has(require_run_tasks.normalizeOutputPathKey(file)) : false);
|
|
2008
2075
|
};
|
|
2009
2076
|
const recordGeneratorCandidates = (candidates) => {
|
|
2010
2077
|
recordedGeneratorCandidates = new Set(candidates);
|
|
@@ -2191,9 +2258,9 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
2191
2258
|
return plugins;
|
|
2192
2259
|
}
|
|
2193
2260
|
//#endregion
|
|
2194
|
-
Object.defineProperty(exports, "
|
|
2261
|
+
Object.defineProperty(exports, "WeappTailwindcss", {
|
|
2195
2262
|
enumerable: true,
|
|
2196
2263
|
get: function() {
|
|
2197
|
-
return
|
|
2264
|
+
return WeappTailwindcss;
|
|
2198
2265
|
}
|
|
2199
2266
|
});
|