tailwindcss-injector 0.0.1 → 0.0.2

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 ADDED
@@ -0,0 +1,112 @@
1
+ # TailwindCSS Injector
2
+
3
+ **English | [中文](./README-cn.md)**
4
+
5
+ - [TailwindCSS Injector](#tailwindcss-injector)
6
+ - [Overview](#overview)
7
+ - [Features](#features)
8
+ - [Installation](#installation)
9
+ - [Usage](#usage)
10
+ - [Basic Example](#basic-example)
11
+ - [Options](#options)
12
+ - [Example Configuration](#example-configuration)
13
+ - [How It Works](#how-it-works)
14
+ - [License](#license)
15
+
16
+ ---
17
+
18
+ ## Overview
19
+
20
+ `tailwindcss-injector` is a library designed to dynamically inject TailwindCSS directives and configurations into your CSS workflow. It includes a PostCSS plugin that supports multiple file extensions, dynamic configuration, and flexible filtering, enabling seamless integration into modern build pipelines.
21
+
22
+ ---
23
+
24
+ ## Features
25
+
26
+ - **Dynamic Directive Injection**: Automatically inserts TailwindCSS directives like `@tailwind base`, `@tailwind components`, and `@tailwind utilities`.
27
+ - **Multi-extension Support**: Processes files with customizable extensions (e.g., `.html`, `.js`, `.ts`).
28
+ - **Inline or External Configuration**: Accepts inline configuration objects or paths to configuration files.
29
+ - **Customizable Filters**: Use a filter function to process specific files.
30
+ - **TailwindCSS Integration**: Dynamically adjusts TailwindCSS configurations per file.
31
+
32
+ ---
33
+
34
+ ## Installation
35
+
36
+ Install the package and its dependencies:
37
+
38
+ ```bash
39
+ npm install tailwindcss-injector tailwindcss postcss --save-dev
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Usage
45
+
46
+ To use the PostCSS plugin, import it from `tailwindcss-injector/postcss`:
47
+
48
+ ### Basic Example
49
+
50
+ ```javascript
51
+ const tailwindInjector = require('tailwindcss-injector/postcss')
52
+
53
+ module.exports = {
54
+ plugins: [
55
+ tailwindInjector({
56
+ cwd: process.cwd(),
57
+ config: './tailwind.config.js',
58
+ directiveParams: ['base', 'components', 'utilities'],
59
+ extensions: ['html', 'js', 'ts'],
60
+ filter: input => !!input?.file && input.file.endsWith('.css'),
61
+ }),
62
+ ],
63
+ }
64
+ ```
65
+
66
+ ---
67
+
68
+ ## Options
69
+
70
+ The plugin accepts the following options:
71
+
72
+ | Option | Type | Description |
73
+ | ----------------- | ------------------------------------------------------------------ | ------------------------------------------------------------------- |
74
+ | `cwd` | `string` | Current working directory. |
75
+ | `config` | `string \| Partial<Config> \| (input) => InlineTailwindcssOptions` | TailwindCSS configuration file path or inline configuration object. |
76
+ | `directiveParams` | `('base' \| 'components' \| 'utilities' \| 'variants')[]` | Array of TailwindCSS directives to inject. |
77
+ | `extensions` | `string[]` | Array of supported file extensions. |
78
+ | `filter` | `(input?: postcss.Input) => boolean` | Custom function to filter files to process. |
79
+
80
+ ### Example Configuration
81
+
82
+ ```javascript
83
+ {
84
+ cwd: process.cwd(), // Set current working directory
85
+ config: './tailwind.config.js', // Use an external TailwindCSS configuration file
86
+ directiveParams: ['base', 'components', 'utilities'], // Inject directives dynamically
87
+ extensions: ['html', 'js', 'ts'], // Process specific file extensions
88
+ filter: (input) => !!input?.file && input.file.endsWith('.css'), // Filter for CSS files only
89
+ }
90
+ ```
91
+
92
+ ---
93
+
94
+ ## How It Works
95
+
96
+ 1. **Directive Injection**:
97
+ The plugin ensures that the specified TailwindCSS directives (`@tailwind base`, `@tailwind components`, etc.) are injected into the CSS files.
98
+
99
+ 2. **Dynamic Configuration**:
100
+ TailwindCSS configurations are dynamically adjusted based on the processed files, including custom extensions.
101
+
102
+ 3. **File Filtering**:
103
+ Files to process can be filtered using the `filter` option.
104
+
105
+ 4. **PostCSS Processing**:
106
+ The plugin integrates with PostCSS to apply TailwindCSS transformations seamlessly.
107
+
108
+ ---
109
+
110
+ ## License
111
+
112
+ This project is licensed under the **MIT License**. See the `LICENSE` file for details.
package/dist/postcss.cjs CHANGED
@@ -218,7 +218,21 @@ var require_set_value = __commonJS({
218
218
 
219
219
  // src/postcss.ts
220
220
  init_cjs_shims();
221
+ var import_set_value = __toESM(require_set_value(), 1);
221
222
  var _process = require('process'); var _process2 = _interopRequireDefault(_process);
223
+ var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
224
+ var _tailwindcss = require('tailwindcss'); var _tailwindcss2 = _interopRequireDefault(_tailwindcss);
225
+
226
+ // src/config.ts
227
+ init_cjs_shims();
228
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
229
+
230
+ var _jiti = require('jiti');
231
+ var _lilconfig = require('lilconfig');
232
+
233
+ // src/utils.ts
234
+ init_cjs_shims();
235
+
222
236
 
223
237
  // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
224
238
  init_cjs_shims();
@@ -289,21 +303,27 @@ var defuArrayFn = createDefu((object, key, currentValue) => {
289
303
  }
290
304
  });
291
305
 
292
- // src/postcss.ts
293
- var import_set_value = __toESM(require_set_value(), 1);
294
- var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
295
- var _tailwindcss = require('tailwindcss'); var _tailwindcss2 = _interopRequireDefault(_tailwindcss);
306
+ // src/utils.ts
307
+ function removeFileExtension(filePath) {
308
+ let baseName = _path2.default.basename(filePath, _path2.default.extname(filePath));
309
+ while (baseName.includes(".")) {
310
+ baseName = _path2.default.basename(baseName, _path2.default.extname(baseName));
311
+ }
312
+ const dir = _path2.default.dirname(filePath);
313
+ return _path2.default.join(dir, baseName);
314
+ }
315
+ var defuOverrideArray = createDefu((obj, key, value) => {
316
+ if (Array.isArray(obj[key]) && Array.isArray(value)) {
317
+ obj[key] = value;
318
+ return true;
319
+ }
320
+ });
296
321
 
297
322
  // src/config.ts
298
- init_cjs_shims();
299
- var _path = require('path'); var _path2 = _interopRequireDefault(_path);
300
-
301
- var _jiti = require('jiti');
302
- var _lilconfig = require('lilconfig');
303
323
  var jiti = _jiti.createJiti.call(void 0, importMetaUrl);
304
324
  var moduleName = "tailwind";
305
325
  async function loadConfig(options) {
306
- const { config, cwd } = defu(options, {
326
+ const { config, cwd } = defuOverrideArray(options, {
307
327
  cwd: _process2.default.cwd()
308
328
  });
309
329
  const searcher = _lilconfig.lilconfig.call(void 0, "tailwindcss", {
@@ -334,24 +354,12 @@ async function loadConfig(options) {
334
354
  }
335
355
  }
336
356
 
337
- // src/utils.ts
338
- init_cjs_shims();
339
-
340
- function removeFileExtension(filePath) {
341
- let baseName = _path2.default.basename(filePath, _path2.default.extname(filePath));
342
- while (baseName.includes(".")) {
343
- baseName = _path2.default.basename(baseName, _path2.default.extname(baseName));
344
- }
345
- const dir = _path2.default.dirname(filePath);
346
- return _path2.default.join(dir, baseName);
347
- }
348
-
349
357
  // src/postcss.ts
350
358
  var creator = (options) => {
351
- const { config, filter, directiveParams, cwd, extensions } = defu(options, {
359
+ const { config, filter, directiveParams, cwd, extensions } = defuOverrideArray(options, {
352
360
  filter: () => true,
353
361
  config: void 0,
354
- directiveParams: ["utilities"],
362
+ directiveParams: ["utilities", "components"],
355
363
  cwd: _process2.default.cwd(),
356
364
  extensions: ["wxml", "js", "ts"]
357
365
  });
@@ -1,7 +1,7 @@
1
1
  import postcss, { PluginCreator } from 'postcss';
2
2
  import { Config } from 'tailwindcss';
3
3
 
4
- type InlineTailwindcssOptions = string | Config | undefined;
4
+ type InlineTailwindcssOptions = string | Partial<Config> | undefined;
5
5
  interface Options {
6
6
  cwd: string;
7
7
  filter: (input?: postcss.Input) => boolean;
package/dist/postcss.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import postcss, { PluginCreator } from 'postcss';
2
2
  import { Config } from 'tailwindcss';
3
3
 
4
- type InlineTailwindcssOptions = string | Config | undefined;
4
+ type InlineTailwindcssOptions = string | Partial<Config> | undefined;
5
5
  interface Options {
6
6
  cwd: string;
7
7
  filter: (input?: postcss.Input) => boolean;
package/dist/postcss.js CHANGED
@@ -215,7 +215,21 @@ var require_set_value = __commonJS({
215
215
 
216
216
  // src/postcss.ts
217
217
  init_esm_shims();
218
+ var import_set_value = __toESM(require_set_value(), 1);
218
219
  import process2 from "node:process";
220
+ import postcss from "postcss";
221
+ import tailwindcss from "tailwindcss";
222
+
223
+ // src/config.ts
224
+ init_esm_shims();
225
+ import path2 from "node:path";
226
+ import process from "node:process";
227
+ import { createJiti } from "jiti";
228
+ import { lilconfig } from "lilconfig";
229
+
230
+ // src/utils.ts
231
+ init_esm_shims();
232
+ import path from "node:path";
219
233
 
220
234
  // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
221
235
  init_esm_shims();
@@ -286,21 +300,27 @@ var defuArrayFn = createDefu((object, key, currentValue) => {
286
300
  }
287
301
  });
288
302
 
289
- // src/postcss.ts
290
- var import_set_value = __toESM(require_set_value(), 1);
291
- import postcss from "postcss";
292
- import tailwindcss from "tailwindcss";
303
+ // src/utils.ts
304
+ function removeFileExtension(filePath) {
305
+ let baseName = path.basename(filePath, path.extname(filePath));
306
+ while (baseName.includes(".")) {
307
+ baseName = path.basename(baseName, path.extname(baseName));
308
+ }
309
+ const dir = path.dirname(filePath);
310
+ return path.join(dir, baseName);
311
+ }
312
+ var defuOverrideArray = createDefu((obj, key, value) => {
313
+ if (Array.isArray(obj[key]) && Array.isArray(value)) {
314
+ obj[key] = value;
315
+ return true;
316
+ }
317
+ });
293
318
 
294
319
  // src/config.ts
295
- init_esm_shims();
296
- import path from "node:path";
297
- import process from "node:process";
298
- import { createJiti } from "jiti";
299
- import { lilconfig } from "lilconfig";
300
320
  var jiti = createJiti(import.meta.url);
301
321
  var moduleName = "tailwind";
302
322
  async function loadConfig(options) {
303
- const { config, cwd } = defu(options, {
323
+ const { config, cwd } = defuOverrideArray(options, {
304
324
  cwd: process.cwd()
305
325
  });
306
326
  const searcher = lilconfig("tailwindcss", {
@@ -322,7 +342,7 @@ async function loadConfig(options) {
322
342
  }
323
343
  });
324
344
  if (typeof config === "string" && config) {
325
- const configPath = path.isAbsolute(config) ? config : path.resolve(cwd, config);
345
+ const configPath = path2.isAbsolute(config) ? config : path2.resolve(cwd, config);
326
346
  const result = await searcher.load(configPath);
327
347
  return result?.config;
328
348
  } else {
@@ -331,24 +351,12 @@ async function loadConfig(options) {
331
351
  }
332
352
  }
333
353
 
334
- // src/utils.ts
335
- init_esm_shims();
336
- import path2 from "node:path";
337
- function removeFileExtension(filePath) {
338
- let baseName = path2.basename(filePath, path2.extname(filePath));
339
- while (baseName.includes(".")) {
340
- baseName = path2.basename(baseName, path2.extname(baseName));
341
- }
342
- const dir = path2.dirname(filePath);
343
- return path2.join(dir, baseName);
344
- }
345
-
346
354
  // src/postcss.ts
347
355
  var creator = (options) => {
348
- const { config, filter, directiveParams, cwd, extensions } = defu(options, {
356
+ const { config, filter, directiveParams, cwd, extensions } = defuOverrideArray(options, {
349
357
  filter: () => true,
350
358
  config: void 0,
351
- directiveParams: ["utilities"],
359
+ directiveParams: ["utilities", "components"],
352
360
  cwd: process2.cwd(),
353
361
  extensions: ["wxml", "js", "ts"]
354
362
  });
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "tailwindcss-injector",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "description": "tsup(esbuild) build package template",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/sonofmagic/monorepo-template.git",
11
- "directory": "packages/bar"
10
+ "url": "git+https://github.com/sonofmagic/weapp-tailwindcss.git",
11
+ "directory": "packages/tailwindcss-injector"
12
12
  },
13
13
  "bugs": {
14
- "url": "https://github.com/sonofmagic/monorepo-template/issues"
14
+ "url": "https://github.com/sonofmagic/weapp-tailwindcss/issues"
15
15
  },
16
16
  "keywords": [],
17
17
  "sideEffects": false,
@@ -32,7 +32,7 @@
32
32
  ],
33
33
  "dependencies": {
34
34
  "jiti": "^2.4.1",
35
- "lilconfig": "^3.1.2",
35
+ "lilconfig": "^3.1.3",
36
36
  "postcss": "^8.4.49",
37
37
  "tailwindcss": "^3.4.15"
38
38
  },