tailwindcss-injector 0.1.2 → 0.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.
- package/dist/postcss.cjs +40 -16
- package/dist/postcss.d.cts +1 -0
- package/dist/postcss.d.ts +1 -0
- package/dist/postcss.js +40 -16
- package/package.json +2 -2
package/dist/postcss.cjs
CHANGED
|
@@ -216,11 +216,14 @@ var require_set_value = __commonJS({
|
|
|
216
216
|
// src/postcss.ts
|
|
217
217
|
init_cjs_shims();
|
|
218
218
|
var import_set_value = __toESM(require_set_value(), 1);
|
|
219
|
-
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
220
219
|
var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
|
|
221
220
|
var _tailwindcss = require('tailwindcss'); var _tailwindcss2 = _interopRequireDefault(_tailwindcss);
|
|
222
221
|
var _tailwindcssconfig = require('tailwindcss-config');
|
|
223
222
|
|
|
223
|
+
// src/config.ts
|
|
224
|
+
init_cjs_shims();
|
|
225
|
+
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
226
|
+
|
|
224
227
|
// src/utils.ts
|
|
225
228
|
init_cjs_shims();
|
|
226
229
|
var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
|
|
@@ -321,6 +324,27 @@ function md5(input) {
|
|
|
321
324
|
return hash.digest("hex");
|
|
322
325
|
}
|
|
323
326
|
|
|
327
|
+
// src/config.ts
|
|
328
|
+
function getDefaultConfig() {
|
|
329
|
+
return {
|
|
330
|
+
filter: () => true,
|
|
331
|
+
config: void 0,
|
|
332
|
+
// 倒叙插入
|
|
333
|
+
directiveParams: ["utilities", "components"],
|
|
334
|
+
cwd: _process2.default.cwd(),
|
|
335
|
+
extensions: ["wxml", "js", "ts"],
|
|
336
|
+
// @import and @use (scss)
|
|
337
|
+
insertAfterAtRulesNames: ["import", "use"]
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function getConfig(options) {
|
|
341
|
+
return defuOverrideArray(options, getDefaultConfig());
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/constants.ts
|
|
345
|
+
init_cjs_shims();
|
|
346
|
+
var postcssPlugin = "postcss-tailwindcss-injector";
|
|
347
|
+
|
|
324
348
|
// src/wxml.ts
|
|
325
349
|
init_cjs_shims();
|
|
326
350
|
|
|
@@ -419,25 +443,25 @@ async function getDepFiles(file) {
|
|
|
419
443
|
|
|
420
444
|
// src/postcss.ts
|
|
421
445
|
var creator = (options) => {
|
|
422
|
-
const { config, filter, directiveParams, cwd, extensions } =
|
|
423
|
-
filter: () => true,
|
|
424
|
-
config: void 0,
|
|
425
|
-
directiveParams: ["utilities", "components"],
|
|
426
|
-
cwd: _process2.default.cwd(),
|
|
427
|
-
extensions: ["wxml", "js", "ts"]
|
|
428
|
-
});
|
|
446
|
+
const { config, filter, directiveParams, cwd, extensions, insertAfterAtRulesNames } = getConfig(options);
|
|
429
447
|
const extensionsGlob = `{${extensions.join(",")}}`;
|
|
430
448
|
return {
|
|
431
|
-
postcssPlugin
|
|
449
|
+
postcssPlugin,
|
|
432
450
|
plugins: [
|
|
433
451
|
{
|
|
434
|
-
postcssPlugin:
|
|
452
|
+
postcssPlugin: `${postcssPlugin}:post`,
|
|
435
453
|
async Once(root, helpers) {
|
|
436
454
|
if (filter(_optionalChain([root, 'access', _ => _.source, 'optionalAccess', _2 => _2.input]))) {
|
|
455
|
+
const lastIndex = root.nodes.findLastIndex((x) => x.type === "atrule" && insertAfterAtRulesNames.includes(x.name));
|
|
437
456
|
for (const params of directiveParams) {
|
|
438
457
|
const node = root.nodes.find((x) => x.type === "atrule" && x.params === params);
|
|
439
458
|
if (!node) {
|
|
440
|
-
|
|
459
|
+
const atRule = helpers.atRule({ name: "tailwind", params });
|
|
460
|
+
if (lastIndex < 0) {
|
|
461
|
+
root.prepend(atRule);
|
|
462
|
+
} else {
|
|
463
|
+
root.insertAfter(lastIndex, atRule);
|
|
464
|
+
}
|
|
441
465
|
}
|
|
442
466
|
}
|
|
443
467
|
const cfg = typeof config === "function" ? config(_optionalChain([root, 'access', _3 => _3.source, 'optionalAccess', _4 => _4.input])) : config;
|
|
@@ -463,12 +487,12 @@ var creator = (options) => {
|
|
|
463
487
|
tailwindcssConfig.content.push(`${removeFileExtension(dep)}.${extensionsGlob}`);
|
|
464
488
|
}
|
|
465
489
|
}
|
|
490
|
+
await _postcss2.default.call(void 0, [
|
|
491
|
+
_tailwindcss2.default.call(void 0, tailwindcssConfig)
|
|
492
|
+
]).process(root, {
|
|
493
|
+
from: root.source.input.file
|
|
494
|
+
});
|
|
466
495
|
}
|
|
467
|
-
await _postcss2.default.call(void 0, [
|
|
468
|
-
_tailwindcss2.default.call(void 0, tailwindcssConfig)
|
|
469
|
-
]).process(root, {
|
|
470
|
-
from: _optionalChain([root, 'access', _7 => _7.source, 'optionalAccess', _8 => _8.input, 'access', _9 => _9.file])
|
|
471
|
-
});
|
|
472
496
|
}
|
|
473
497
|
}
|
|
474
498
|
}
|
package/dist/postcss.d.cts
CHANGED
|
@@ -8,6 +8,7 @@ interface Options {
|
|
|
8
8
|
config: InlineTailwindcssOptions | ((input?: postcss.Input) => InlineTailwindcssOptions);
|
|
9
9
|
directiveParams: ('base' | 'components' | 'utilities' | 'variants')[];
|
|
10
10
|
extensions: string[];
|
|
11
|
+
insertAfterAtRulesNames: string[];
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
declare const creator: PluginCreator<Partial<Options>>;
|
package/dist/postcss.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ interface Options {
|
|
|
8
8
|
config: InlineTailwindcssOptions | ((input?: postcss.Input) => InlineTailwindcssOptions);
|
|
9
9
|
directiveParams: ('base' | 'components' | 'utilities' | 'variants')[];
|
|
10
10
|
extensions: string[];
|
|
11
|
+
insertAfterAtRulesNames: string[];
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
declare const creator: PluginCreator<Partial<Options>>;
|
package/dist/postcss.js
CHANGED
|
@@ -216,11 +216,14 @@ var require_set_value = __commonJS({
|
|
|
216
216
|
// src/postcss.ts
|
|
217
217
|
init_esm_shims();
|
|
218
218
|
var import_set_value = __toESM(require_set_value(), 1);
|
|
219
|
-
import process from "node:process";
|
|
220
219
|
import postcss from "postcss";
|
|
221
220
|
import tailwindcss from "tailwindcss";
|
|
222
221
|
import { loadConfig } from "tailwindcss-config";
|
|
223
222
|
|
|
223
|
+
// src/config.ts
|
|
224
|
+
init_esm_shims();
|
|
225
|
+
import process from "node:process";
|
|
226
|
+
|
|
224
227
|
// src/utils.ts
|
|
225
228
|
init_esm_shims();
|
|
226
229
|
import crypto from "node:crypto";
|
|
@@ -321,6 +324,27 @@ function md5(input) {
|
|
|
321
324
|
return hash.digest("hex");
|
|
322
325
|
}
|
|
323
326
|
|
|
327
|
+
// src/config.ts
|
|
328
|
+
function getDefaultConfig() {
|
|
329
|
+
return {
|
|
330
|
+
filter: () => true,
|
|
331
|
+
config: void 0,
|
|
332
|
+
// 倒叙插入
|
|
333
|
+
directiveParams: ["utilities", "components"],
|
|
334
|
+
cwd: process.cwd(),
|
|
335
|
+
extensions: ["wxml", "js", "ts"],
|
|
336
|
+
// @import and @use (scss)
|
|
337
|
+
insertAfterAtRulesNames: ["import", "use"]
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function getConfig(options) {
|
|
341
|
+
return defuOverrideArray(options, getDefaultConfig());
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/constants.ts
|
|
345
|
+
init_esm_shims();
|
|
346
|
+
var postcssPlugin = "postcss-tailwindcss-injector";
|
|
347
|
+
|
|
324
348
|
// src/wxml.ts
|
|
325
349
|
init_esm_shims();
|
|
326
350
|
import path2 from "node:path";
|
|
@@ -419,25 +443,25 @@ async function getDepFiles(file) {
|
|
|
419
443
|
|
|
420
444
|
// src/postcss.ts
|
|
421
445
|
var creator = (options) => {
|
|
422
|
-
const { config, filter, directiveParams, cwd, extensions } =
|
|
423
|
-
filter: () => true,
|
|
424
|
-
config: void 0,
|
|
425
|
-
directiveParams: ["utilities", "components"],
|
|
426
|
-
cwd: process.cwd(),
|
|
427
|
-
extensions: ["wxml", "js", "ts"]
|
|
428
|
-
});
|
|
446
|
+
const { config, filter, directiveParams, cwd, extensions, insertAfterAtRulesNames } = getConfig(options);
|
|
429
447
|
const extensionsGlob = `{${extensions.join(",")}}`;
|
|
430
448
|
return {
|
|
431
|
-
postcssPlugin
|
|
449
|
+
postcssPlugin,
|
|
432
450
|
plugins: [
|
|
433
451
|
{
|
|
434
|
-
postcssPlugin:
|
|
452
|
+
postcssPlugin: `${postcssPlugin}:post`,
|
|
435
453
|
async Once(root, helpers) {
|
|
436
454
|
if (filter(root.source?.input)) {
|
|
455
|
+
const lastIndex = root.nodes.findLastIndex((x) => x.type === "atrule" && insertAfterAtRulesNames.includes(x.name));
|
|
437
456
|
for (const params of directiveParams) {
|
|
438
457
|
const node = root.nodes.find((x) => x.type === "atrule" && x.params === params);
|
|
439
458
|
if (!node) {
|
|
440
|
-
|
|
459
|
+
const atRule = helpers.atRule({ name: "tailwind", params });
|
|
460
|
+
if (lastIndex < 0) {
|
|
461
|
+
root.prepend(atRule);
|
|
462
|
+
} else {
|
|
463
|
+
root.insertAfter(lastIndex, atRule);
|
|
464
|
+
}
|
|
441
465
|
}
|
|
442
466
|
}
|
|
443
467
|
const cfg = typeof config === "function" ? config(root.source?.input) : config;
|
|
@@ -463,12 +487,12 @@ var creator = (options) => {
|
|
|
463
487
|
tailwindcssConfig.content.push(`${removeFileExtension(dep)}.${extensionsGlob}`);
|
|
464
488
|
}
|
|
465
489
|
}
|
|
490
|
+
await postcss([
|
|
491
|
+
tailwindcss(tailwindcssConfig)
|
|
492
|
+
]).process(root, {
|
|
493
|
+
from: root.source.input.file
|
|
494
|
+
});
|
|
466
495
|
}
|
|
467
|
-
await postcss([
|
|
468
|
-
tailwindcss(tailwindcssConfig)
|
|
469
|
-
]).process(root, {
|
|
470
|
-
from: root.source?.input.file
|
|
471
|
-
});
|
|
472
496
|
}
|
|
473
497
|
}
|
|
474
498
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-injector",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"description": "tsup(esbuild) build package template",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"fs-extra": "^11.2.0",
|
|
35
35
|
"htmlparser2": "^9.1.0",
|
|
36
|
-
"magic-string": "^0.30.
|
|
36
|
+
"magic-string": "^0.30.15",
|
|
37
37
|
"postcss": "^8.4.49",
|
|
38
38
|
"tailwindcss": "^3.4.16",
|
|
39
39
|
"tailwindcss-config": "0.0.0"
|