@vituum/vite-plugin-tailwindcss 1.0.0-alpha.1
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/LICENSE +21 -0
- package/README.md +32 -0
- package/index.js +53 -0
- package/package.json +42 -0
- package/types/index.d.ts +7 -0
- package/types/postcssImport.d.ts +91 -0
- package/types/viteUserConfig.d.ts +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Vituum
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<a href="https://npmjs.com/package/@vituum/vite-plugin-tailwind"><img src="https://img.shields.io/npm/v/@vituum/vite-plugin-tailwind.svg" alt="npm package"></a>
|
|
2
|
+
<a href="https://nodejs.org/en/about/releases/"><img src="https://img.shields.io/node/v/@vituum/vite-plugin-tailwind.svg" alt="node compatility"></a>
|
|
3
|
+
|
|
4
|
+
# ⚡️🎨 ViteTailwindCSS
|
|
5
|
+
Adds out of the box support for TailwindCSS with following PostCSS plugins:
|
|
6
|
+
* [`postcss-import`](https://www.npmjs.com/package/postcss-import)
|
|
7
|
+
* [`postcss-nesting`](https://www.npmjs.com/package/postcss-nesting)
|
|
8
|
+
* [`postcss-custom-media`](https://www.npmjs.com/package/postcss-custom-media)
|
|
9
|
+
* [`autoprefixer`](https://www.npmjs.com/package/autoprefixer)
|
|
10
|
+
|
|
11
|
+
## Basic usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import tailwindcss from '@vituum/vite-plugin-tailwindcss'
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
plugins: [
|
|
18
|
+
tailwindcss()
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
* Don't forget to also add your `tailwind.config.js`, [learn more here](https://tailwindcss.com/docs/guides/vite).
|
|
24
|
+
* If you want to add more PostCSS plugins, use add the via [css.postcss.plugins](https://vitejs.dev/config/shared-options.html#css-postcss).
|
|
25
|
+
* If you want to use `postcss.config.cjs` add `css.postcss: process.cwd()`, PostCSS config and it's plugins will be used instead
|
|
26
|
+
|
|
27
|
+
Read the [docs](https://vituum.dev/config/plugins-options.html#vituum-postcss) to learn more about plugin options
|
|
28
|
+
|
|
29
|
+
### Requirements
|
|
30
|
+
|
|
31
|
+
- [Node.js LTS (18.x)](https://nodejs.org/en/download/)
|
|
32
|
+
- [Vite](https://vitejs.dev/)
|
package/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import postcssImport from 'postcss-import'
|
|
2
|
+
import postcssNesting from 'postcss-nesting'
|
|
3
|
+
import postcssCustomMedia from 'postcss-custom-media'
|
|
4
|
+
import tailwindcss from 'tailwindcss'
|
|
5
|
+
import tailwindcssNesting from 'tailwindcss/nesting'
|
|
6
|
+
import autoprefixer from 'autoprefixer'
|
|
7
|
+
import { getPackageInfo, merge } from 'vituum/utils/common.js'
|
|
8
|
+
|
|
9
|
+
const { name } = getPackageInfo(import.meta.url)
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @type {import('@vituum/vite-plugin-tailwind/types/index').PluginUserConfig}
|
|
13
|
+
*/
|
|
14
|
+
const defaultOptions = {
|
|
15
|
+
import: {},
|
|
16
|
+
nesting: {},
|
|
17
|
+
customMedia: {},
|
|
18
|
+
autoprefixer: {},
|
|
19
|
+
tailwindcss: undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {import('@vituum/vite-plugin-tailwind/types/index').PluginUserConfig} options
|
|
24
|
+
* @returns {import('vite').Plugin}
|
|
25
|
+
*/
|
|
26
|
+
const plugin = (options = {}) => {
|
|
27
|
+
options = merge(defaultOptions, options)
|
|
28
|
+
|
|
29
|
+
const postcssPlugins = [
|
|
30
|
+
postcssImport(options.import),
|
|
31
|
+
tailwindcssNesting(postcssNesting(options.nesting)),
|
|
32
|
+
postcssCustomMedia(options.customMedia),
|
|
33
|
+
tailwindcss(options.tailwindcss),
|
|
34
|
+
autoprefixer(options.autoprefixer)
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
name,
|
|
39
|
+
enforce: 'pre',
|
|
40
|
+
/** @param {import('@vituum/vite-plugin-tailwind/types/viteUserConfig').ViteUserConfig} userConfig */
|
|
41
|
+
config (userConfig) {
|
|
42
|
+
if (!userConfig?.css?.postcss && !userConfig?.css?.postcss?.plugins) {
|
|
43
|
+
userConfig.css = userConfig.css || {}
|
|
44
|
+
userConfig.css.postcss = userConfig.css.postcss || {}
|
|
45
|
+
userConfig.css.postcss.plugins = postcssPlugins
|
|
46
|
+
} else if (userConfig.css.postcss.plugins) {
|
|
47
|
+
userConfig.css.postcss.plugins = postcssPlugins.concat(...userConfig.css.postcss.plugins)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export default plugin
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vituum/vite-plugin-tailwindcss",
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"tsc": "tsc",
|
|
8
|
+
"eslint": "eslint '**/*.js' --fix"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"vituum": "^1.0.0-alpha.16",
|
|
12
|
+
"autoprefixer": "^10.4.14",
|
|
13
|
+
"postcss": "^8.4.24",
|
|
14
|
+
"postcss-import": "^15.1.0",
|
|
15
|
+
"postcss-nesting": "^11.3.0",
|
|
16
|
+
"postcss-custom-media": "^9.1.4",
|
|
17
|
+
"tailwindcss": "^3.3.2"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^20.3.1",
|
|
21
|
+
"vite": "^4.3.9",
|
|
22
|
+
"eslint": "^8.43.0",
|
|
23
|
+
"eslint-config-standard": "^17.1.0",
|
|
24
|
+
"typescript": "^5.1.3"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"index.js",
|
|
28
|
+
"types"
|
|
29
|
+
],
|
|
30
|
+
"exports": {
|
|
31
|
+
".": "./index.js",
|
|
32
|
+
"./types": "./types/*"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18.0.0",
|
|
36
|
+
"npm": ">=9.0.0"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/vituum/vite-plugin-tailwind.git"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface PluginUserConfig {
|
|
2
|
+
import?: import('@vituum/vite-plugin-tailwind/types/postcssImport.d.ts').AtImportOptions
|
|
3
|
+
nesting?: import('postcss-nesting').pluginOptions
|
|
4
|
+
customMedia?: import('postcss-custom-media').pluginOptions
|
|
5
|
+
autoprefixer?: import('autoprefixer').Options
|
|
6
|
+
tailwindcss?: import('tailwindcss').Config
|
|
7
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Type definitions for postcss-import 14.0
|
|
2
|
+
// Project: https://github.com/postcss/postcss-import#readme
|
|
3
|
+
// Definitions by: Remco Haszing <https://github.com/remcohaszing>
|
|
4
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
+
|
|
6
|
+
import { AcceptedPlugin, Transformer } from 'postcss';
|
|
7
|
+
|
|
8
|
+
export = atImport;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This plugin can consume local files, node modules or web_modules. To resolve path of an `@import` rule, it can look into root directory (by default `process.cwd()`), `web_modules`, `node_modules`
|
|
12
|
+
* or local modules. _When importing a module, it will look for `index.css` or file referenced in `package.json` in the `style` or `main` fields._ You can also provide manually multiples paths where
|
|
13
|
+
* to look at.
|
|
14
|
+
*
|
|
15
|
+
* **Notes:**
|
|
16
|
+
*
|
|
17
|
+
* - **This plugin should probably be used as the first plugin of your list. This way, other plugins will work on the AST as if there were only a single file to process, and will probably work as you
|
|
18
|
+
* can expect**.
|
|
19
|
+
* - This plugin works great with [postcss-url](https://github.com/postcss/postcss-url) plugin, which will allow you to adjust assets `url()` (or even inline them) after inlining imported files.
|
|
20
|
+
* - In order to optimize output, **this plugin will only import a file once** on a given scope (root, media query…). Tests are made from the path & the content of imported files (using a hash table).
|
|
21
|
+
* If this behavior is not what you want, look at `skipDuplicates` option
|
|
22
|
+
* - **If you are looking for glob, or sass like imports (prefixed partials)**, please look at [postcss-easy-import](https://github.com/trysound/postcss-easy-import) (which use this plugin under the
|
|
23
|
+
* hood).
|
|
24
|
+
* - Imports which are not modified (by `options.filter` or because they are remote imports) are moved to the top of the output.
|
|
25
|
+
* - **This plugin attempts to follow the CSS `@import` spec**; `@import` statements must precede all other statements (besides `@charset`).
|
|
26
|
+
*/
|
|
27
|
+
declare function atImport(options?: atImport.AtImportOptions): Transformer;
|
|
28
|
+
|
|
29
|
+
declare namespace atImport {
|
|
30
|
+
interface AtImportOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Only transform imports for which the test function returns `true`. Imports for which the test function returns `false` will be left as is. The function gets the path to import as an
|
|
33
|
+
* argument and should return a boolean.
|
|
34
|
+
*
|
|
35
|
+
* @default () => true
|
|
36
|
+
*/
|
|
37
|
+
filter?: (path: string) => boolean;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Define the root where to resolve path (eg: place where `node_modules` are). Should not be used that much.
|
|
41
|
+
*
|
|
42
|
+
* _Note: nested @import will additionally benefit of the relative dirname of imported files._
|
|
43
|
+
*
|
|
44
|
+
* Default: `process.cwd()` or dirname of [the postcss from](https://github.com/postcss/postcss#node-source)
|
|
45
|
+
*/
|
|
46
|
+
root?: string | undefined;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A string or an array of paths in where to look for files.
|
|
50
|
+
*/
|
|
51
|
+
path?: string | string[] | undefined;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* An array of plugins to be applied on each imported files.
|
|
55
|
+
*/
|
|
56
|
+
plugins?: AcceptedPlugin[] | undefined;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* You can provide a custom path resolver with this option. This function gets `(id, basedir, importOptions)` arguments and should return a path, an array of paths or a promise resolving to
|
|
60
|
+
* the path(s). If you do not return an absolute path, your path will be resolved to an absolute path using the default resolver. You can use
|
|
61
|
+
* [resolve](https://github.com/substack/node-resolve) for this.
|
|
62
|
+
*/
|
|
63
|
+
resolve?:
|
|
64
|
+
| ((
|
|
65
|
+
id: string,
|
|
66
|
+
basedir: string,
|
|
67
|
+
importOptions: AtImportOptions,
|
|
68
|
+
) => string | string[] | PromiseLike<string | string[]>)
|
|
69
|
+
| undefined;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* You can overwrite the default loading way by setting this option. This function gets `(filename, importOptions)` arguments and returns content or promised content.
|
|
73
|
+
*/
|
|
74
|
+
load?: ((filename: string, importOptions: AtImportOptions) => string | Promise<string>) | undefined;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* By default, similar files (based on the same content) are being skipped. It's to optimize output and skip similar files like `normalize.css` for example. If this behavior is not what you
|
|
78
|
+
* want, just set this option to false to disable it.
|
|
79
|
+
*
|
|
80
|
+
* @default true
|
|
81
|
+
*/
|
|
82
|
+
skipDuplicates?: boolean | undefined;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* An array of folder names to add to Node's resolver. Values will be appended to the default resolve directories: `["node_modules", "web_modules"]`.
|
|
86
|
+
*
|
|
87
|
+
* This option is only for adding additional directories to default resolver. If you provide your own resolver via the `resolve` configuration option above, then this value will be ignored.
|
|
88
|
+
*/
|
|
89
|
+
addModulesDirectories?: string[] | undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|