@unizap/unicss 1.2.23 → 2.0.0
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 +72 -0
- package/package.json +32 -6
- package/postcss.config.js +7 -0
- package/vite-plugin-unicss.js +83 -0
package/README.md
CHANGED
|
@@ -21,6 +21,8 @@ npm i @unizap/unicss
|
|
|
21
21
|
|
|
22
22
|
## ⚡ Usage
|
|
23
23
|
|
|
24
|
+
### CLI Usage
|
|
25
|
+
|
|
24
26
|
Generate your CSS file:
|
|
25
27
|
|
|
26
28
|
```sh
|
|
@@ -33,6 +35,50 @@ Or watch for changes and output to a custom file:
|
|
|
33
35
|
npx unicss -w -o src/output.css
|
|
34
36
|
```
|
|
35
37
|
|
|
38
|
+
### Vite Integration
|
|
39
|
+
|
|
40
|
+
UniCSS now supports seamless integration with Vite! Add the plugin to your `vite.config.js`:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import { defineConfig } from 'vite';
|
|
44
|
+
import unicss from '@unizap/unicss/vite-plugin-unicss';
|
|
45
|
+
|
|
46
|
+
export default defineConfig({
|
|
47
|
+
plugins: [
|
|
48
|
+
unicss({
|
|
49
|
+
output: 'src/unicss.css', // Output path for generated CSS
|
|
50
|
+
skipBase: false // Optional: skip base styles
|
|
51
|
+
})
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Then import the generated CSS in your main entry file:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import './unicss.css';
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Run Vite in development mode:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
npm run dev
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The plugin will:
|
|
69
|
+
- Automatically scan all `.html`, `.js`, `.jsx`, `.ts`, `.tsx`, `.vue`, and `.svelte` files
|
|
70
|
+
- Generate CSS based on the utility classes found
|
|
71
|
+
- Regenerate CSS on file changes with Hot Module Replacement (HMR)
|
|
72
|
+
|
|
73
|
+
### PostCSS Support
|
|
74
|
+
|
|
75
|
+
UniCSS includes PostCSS configuration with the following plugins:
|
|
76
|
+
- `postcss-import` - Inline @import rules
|
|
77
|
+
- `postcss-nested` - Unwrap nested rules
|
|
78
|
+
- `autoprefixer` - Add vendor prefixes automatically
|
|
79
|
+
|
|
80
|
+
You can customize the PostCSS configuration by editing `postcss.config.js` in your project root.
|
|
81
|
+
|
|
36
82
|
---
|
|
37
83
|
|
|
38
84
|
## 🧩 Features
|
|
@@ -41,6 +87,32 @@ npx unicss -w -o src/output.css
|
|
|
41
87
|
- Automatic CSS filter utilities (e.g. `blur-lg`, `brightness-150`)
|
|
42
88
|
- Fast, modern, and easy to integrate
|
|
43
89
|
- Supports custom output paths and watch mode
|
|
90
|
+
- Vite plugin for seamless integration
|
|
91
|
+
- PostCSS support with autoprefixer, nesting, and imports
|
|
92
|
+
- Hot module replacement (HMR) in development
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 🔧 Development & Publishing
|
|
97
|
+
|
|
98
|
+
### Building the package
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
npm run build
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
This creates:
|
|
105
|
+
- `dist/index.js` - Node.js bundle for CLI
|
|
106
|
+
- `dist/unicss.min.js` - Browser CDN bundle
|
|
107
|
+
|
|
108
|
+
### Publishing to npm
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
npm run build
|
|
112
|
+
npm publish
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
See [PUBLISHING.md](./PUBLISHING.md) for detailed instructions.
|
|
44
116
|
|
|
45
117
|
---
|
|
46
118
|
|
package/package.json
CHANGED
|
@@ -1,27 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unizap/unicss",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Unicss: Build sleek interfaces straight from your markup. Fast, modern, utility-first CSS framework for rapid UI development.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"unpkg": "dist/unicss.min.js",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./vite-plugin-unicss": {
|
|
14
|
+
"require": "./vite-plugin-unicss.js",
|
|
15
|
+
"default": "./vite-plugin-unicss.js"
|
|
16
|
+
},
|
|
17
|
+
"./postcss.config.js": "./postcss.config.js"
|
|
18
|
+
},
|
|
7
19
|
"bin": {
|
|
8
20
|
"unicss": "bin/index.js"
|
|
9
21
|
},
|
|
10
22
|
"files": [
|
|
11
23
|
"dist/index.js",
|
|
12
24
|
"dist/unicss.min.js",
|
|
13
|
-
"bin"
|
|
25
|
+
"bin",
|
|
26
|
+
"vite-plugin-unicss.js",
|
|
27
|
+
"postcss.config.js"
|
|
14
28
|
],
|
|
15
29
|
"scripts": {
|
|
16
30
|
"build": "node build.js",
|
|
17
|
-
"
|
|
31
|
+
"build:vite": "vite build",
|
|
32
|
+
"dev": "vite",
|
|
33
|
+
"preview": "vite preview",
|
|
34
|
+
"test:package": "node test-package.js",
|
|
35
|
+
"prepublishOnly": "npm run build",
|
|
18
36
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
19
37
|
},
|
|
20
38
|
"keywords": [
|
|
21
39
|
"css",
|
|
22
40
|
"utility-first",
|
|
23
41
|
"css-framework",
|
|
24
|
-
"filters"
|
|
42
|
+
"filters",
|
|
43
|
+
"vite",
|
|
44
|
+
"postcss",
|
|
45
|
+
"vite-plugin"
|
|
25
46
|
],
|
|
26
47
|
"author": "Unizap",
|
|
27
48
|
"license": "MIT",
|
|
@@ -30,12 +51,17 @@
|
|
|
30
51
|
"chokidar": "^3.6.0"
|
|
31
52
|
},
|
|
32
53
|
"devDependencies": {
|
|
33
|
-
"esbuild": "^0.25.8",
|
|
34
54
|
"@babel/parser": "^7.28.0",
|
|
35
55
|
"@babel/traverse": "^7.28.0",
|
|
56
|
+
"autoprefixer": "^10.4.21",
|
|
36
57
|
"deepmerge": "^4.3.1",
|
|
58
|
+
"esbuild": "^0.25.8",
|
|
37
59
|
"fs": "0.0.1-security",
|
|
38
60
|
"glob": "^11.0.3",
|
|
39
|
-
"path": "^0.12.7"
|
|
61
|
+
"path": "^0.12.7",
|
|
62
|
+
"postcss": "^8.5.6",
|
|
63
|
+
"postcss-import": "^16.1.1",
|
|
64
|
+
"postcss-nested": "^7.0.2",
|
|
65
|
+
"vite": "^7.1.12"
|
|
40
66
|
}
|
|
41
67
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const generateCSS = require('./dist/index.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Vite plugin for UniCSS integration
|
|
7
|
+
* @param {Object} options - Plugin options
|
|
8
|
+
* @param {string} options.output - Output CSS file path (default: 'src/unicss.css')
|
|
9
|
+
* @param {boolean} options.skipBase - Skip base CSS styles (default: false)
|
|
10
|
+
* @returns {import('vite').Plugin}
|
|
11
|
+
*/
|
|
12
|
+
function unicssPlugin(options = {}) {
|
|
13
|
+
const {
|
|
14
|
+
output = 'src/unicss.css',
|
|
15
|
+
skipBase = false
|
|
16
|
+
} = options;
|
|
17
|
+
|
|
18
|
+
let isWatching = false;
|
|
19
|
+
const outputPath = path.resolve(process.cwd(), output);
|
|
20
|
+
|
|
21
|
+
function generateAndWrite() {
|
|
22
|
+
try {
|
|
23
|
+
const css = generateCSS({ skipBase });
|
|
24
|
+
const outDir = path.dirname(outputPath);
|
|
25
|
+
|
|
26
|
+
if (!fs.existsSync(outDir)) {
|
|
27
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fs.writeFileSync(outputPath, css);
|
|
31
|
+
console.log(`UniCSS generated at ${output}`);
|
|
32
|
+
return true;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error(`UniCSS generation failed: ${error.message}`);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
name: 'vite-plugin-unicss',
|
|
41
|
+
|
|
42
|
+
configResolved(resolvedConfig) {
|
|
43
|
+
// Determine if we're in dev mode (watch mode)
|
|
44
|
+
isWatching = resolvedConfig.command === 'serve';
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
buildStart() {
|
|
48
|
+
// Generate CSS on build start
|
|
49
|
+
if (!generateAndWrite()) {
|
|
50
|
+
this.error('UniCSS generation failed');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Add output file to watch list
|
|
54
|
+
if (fs.existsSync(outputPath)) {
|
|
55
|
+
this.addWatchFile(outputPath);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
handleHotUpdate({ file, server }) {
|
|
60
|
+
// Regenerate CSS when watched files change
|
|
61
|
+
if (isWatching && (
|
|
62
|
+
file.endsWith('.html') ||
|
|
63
|
+
file.endsWith('.js') ||
|
|
64
|
+
file.endsWith('.jsx') ||
|
|
65
|
+
file.endsWith('.ts') ||
|
|
66
|
+
file.endsWith('.tsx') ||
|
|
67
|
+
file.endsWith('.vue') ||
|
|
68
|
+
file.endsWith('.svelte')
|
|
69
|
+
)) {
|
|
70
|
+
console.log('File changed, regenerating UniCSS...');
|
|
71
|
+
generateAndWrite();
|
|
72
|
+
|
|
73
|
+
// Trigger HMR for the CSS file
|
|
74
|
+
server.ws.send({
|
|
75
|
+
type: 'full-reload',
|
|
76
|
+
path: '*'
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = unicssPlugin;
|