@zeus-js/output-css 0.1.0-beta.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/dist/output-css.cjs.js +191 -0
- package/dist/output-css.cjs.prod.js +191 -0
- package/dist/output-css.d.ts +53 -0
- package/dist/output-css.esm-bundler.js +253 -0
- package/index.js +4 -0
- package/package.json +73 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* output-css v0.1.0-beta.0
|
|
3
|
+
* (c) 2026 baicie
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
**/
|
|
6
|
+
Object.defineProperties(exports, {
|
|
7
|
+
__esModule: { value: true },
|
|
8
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
9
|
+
});
|
|
10
|
+
//#region \0rolldown/runtime.js
|
|
11
|
+
var __create = Object.create;
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
19
|
+
key = keys[i];
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
+
get: ((k) => from[k]).bind(null, key),
|
|
22
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
//#endregion
|
|
32
|
+
let node_fs_promises = require("node:fs/promises");
|
|
33
|
+
node_fs_promises = __toESM(node_fs_promises, 1);
|
|
34
|
+
let node_path = require("node:path");
|
|
35
|
+
node_path = __toESM(node_path, 1);
|
|
36
|
+
let node_module = require("node:module");
|
|
37
|
+
let node_url = require("node:url");
|
|
38
|
+
//#region packages/web-c/output-css/src/detect.ts
|
|
39
|
+
async function detectCssProcessor(input, root) {
|
|
40
|
+
const ext = node_path.default.extname(input).toLowerCase();
|
|
41
|
+
if (ext === ".scss" || ext === ".sass") return "sass";
|
|
42
|
+
if (ext === ".less") return "less";
|
|
43
|
+
if (ext === ".css") {
|
|
44
|
+
const rootDir = node_path.default.resolve(root);
|
|
45
|
+
if (await hasFile(node_path.default.join(rootDir, "postcss.config.js")) || await hasFile(node_path.default.join(rootDir, "postcss.config.cjs")) || await hasFile(node_path.default.join(rootDir, "postcss.config.mjs")) || await hasFile(node_path.default.join(rootDir, "postcss.config.ts")) || await hasFile(node_path.default.join(rootDir, "tailwind.config.js")) || await hasFile(node_path.default.join(rootDir, "tailwind.config.ts")) || await hasFile(node_path.default.join(rootDir, "tailwind.config.cjs")) || await hasFile(node_path.default.join(rootDir, "tailwind.config.mjs"))) return "postcss";
|
|
46
|
+
return "copy";
|
|
47
|
+
}
|
|
48
|
+
return "copy";
|
|
49
|
+
}
|
|
50
|
+
async function hasFile(file) {
|
|
51
|
+
try {
|
|
52
|
+
const { stat } = await import("node:fs/promises");
|
|
53
|
+
return (await stat(file)).isFile();
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region packages/web-c/output-css/src/processCss.ts
|
|
60
|
+
async function processCssEntry(entry, options, root) {
|
|
61
|
+
const input = node_path.default.resolve(root, entry.input);
|
|
62
|
+
const raw = await node_fs_promises.default.readFile(input, "utf-8");
|
|
63
|
+
const processor = entry.processor === "auto" ? await detectCssProcessor(input, root) : entry.processor;
|
|
64
|
+
let css = raw;
|
|
65
|
+
if (processor === "sass") css = await processSass(input);
|
|
66
|
+
else if (processor === "less") css = await processLess(input, raw);
|
|
67
|
+
else if (processor === "postcss") css = await processPostcss(input, raw, root);
|
|
68
|
+
if (options.minify) css = await minifyCss(input, css);
|
|
69
|
+
return { css };
|
|
70
|
+
}
|
|
71
|
+
async function processSass(input) {
|
|
72
|
+
let sass;
|
|
73
|
+
try {
|
|
74
|
+
sass = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("sass");
|
|
75
|
+
} catch {
|
|
76
|
+
throw new Error("[zeus-output-css] Install \"sass\" to process .scss/.sass files.");
|
|
77
|
+
}
|
|
78
|
+
return (await sass.compileStringAsync(await node_fs_promises.default.readFile(input, "utf-8"), {
|
|
79
|
+
url: (0, node_url.pathToFileURL)(input),
|
|
80
|
+
loadPaths: [node_path.default.dirname(input)]
|
|
81
|
+
})).css;
|
|
82
|
+
}
|
|
83
|
+
async function processLess(input, source) {
|
|
84
|
+
let less;
|
|
85
|
+
try {
|
|
86
|
+
less = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("less");
|
|
87
|
+
} catch {
|
|
88
|
+
throw new Error("[zeus-output-css] Install \"less\" to process .less files.");
|
|
89
|
+
}
|
|
90
|
+
return (await less.render(source, { filename: input })).css;
|
|
91
|
+
}
|
|
92
|
+
async function processPostcss(input, source, root) {
|
|
93
|
+
let postcss;
|
|
94
|
+
try {
|
|
95
|
+
postcss = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("postcss");
|
|
96
|
+
} catch {
|
|
97
|
+
throw new Error("[zeus-output-css] Install \"postcss\" to process CSS with PostCSS.");
|
|
98
|
+
}
|
|
99
|
+
let loadConfig;
|
|
100
|
+
try {
|
|
101
|
+
loadConfig = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("postcss-load-config");
|
|
102
|
+
} catch {
|
|
103
|
+
throw new Error("[zeus-output-css] Install \"postcss-load-config\" to load PostCSS config.");
|
|
104
|
+
}
|
|
105
|
+
const config = await loadConfig({}, root);
|
|
106
|
+
return (await postcss.default(config.plugins).process(source, {
|
|
107
|
+
from: input,
|
|
108
|
+
map: false
|
|
109
|
+
})).css;
|
|
110
|
+
}
|
|
111
|
+
async function minifyCss(_input, source) {
|
|
112
|
+
try {
|
|
113
|
+
let lightningcss;
|
|
114
|
+
lightningcss = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("lightningcss");
|
|
115
|
+
return lightningcss.transform({
|
|
116
|
+
filename: _input,
|
|
117
|
+
code: Buffer.from(source),
|
|
118
|
+
minify: true
|
|
119
|
+
}).code.toString();
|
|
120
|
+
} catch {
|
|
121
|
+
return source;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region packages/web-c/output-css/src/index.ts
|
|
126
|
+
function css(options = {}) {
|
|
127
|
+
const raw = typeof options === "string" ? { input: options } : options;
|
|
128
|
+
let normalized;
|
|
129
|
+
return {
|
|
130
|
+
name: "zeus-output-css",
|
|
131
|
+
async buildStart(ctx) {
|
|
132
|
+
normalized = await normalizeOptions(raw, ctx.root);
|
|
133
|
+
if (normalized.watch) for (const file of normalized.files) ctx.addWatchFile(node_path.default.resolve(ctx.root, file.input));
|
|
134
|
+
},
|
|
135
|
+
async generateBundle(ctx) {
|
|
136
|
+
var _normalized;
|
|
137
|
+
const current = (_normalized = normalized) !== null && _normalized !== void 0 ? _normalized : await normalizeOptions(raw, ctx.root);
|
|
138
|
+
const files = [];
|
|
139
|
+
for (const entry of current.files) {
|
|
140
|
+
const result = await processCssEntry(entry, current, ctx.root);
|
|
141
|
+
files.push({
|
|
142
|
+
type: "asset",
|
|
143
|
+
fileName: entry.fileName,
|
|
144
|
+
source: result.css
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return files;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
async function normalizeOptions(options, root) {
|
|
152
|
+
var _options$minify, _options$watch;
|
|
153
|
+
return {
|
|
154
|
+
files: await normalizeEntries(options, root),
|
|
155
|
+
minify: (_options$minify = options.minify) !== null && _options$minify !== void 0 ? _options$minify : false,
|
|
156
|
+
watch: (_options$watch = options.watch) !== null && _options$watch !== void 0 ? _options$watch : true
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
async function normalizeEntries(options, root) {
|
|
160
|
+
var _options$files, _options$input;
|
|
161
|
+
if ((_options$files = options.files) === null || _options$files === void 0 ? void 0 : _options$files.length) return options.files.map((file) => normalizeEntry(file, options));
|
|
162
|
+
return [normalizeEntry({
|
|
163
|
+
input: (_options$input = options.input) !== null && _options$input !== void 0 ? _options$input : await detectDefaultCssInput(root),
|
|
164
|
+
fileName: options.fileName,
|
|
165
|
+
processor: options.processor
|
|
166
|
+
}, options)];
|
|
167
|
+
}
|
|
168
|
+
function normalizeEntry(entry, options) {
|
|
169
|
+
var _ref, _entry$fileName, _ref2, _entry$processor;
|
|
170
|
+
return {
|
|
171
|
+
input: entry.input,
|
|
172
|
+
fileName: (_ref = (_entry$fileName = entry.fileName) !== null && _entry$fileName !== void 0 ? _entry$fileName : options.fileName) !== null && _ref !== void 0 ? _ref : "styles.css",
|
|
173
|
+
processor: (_ref2 = (_entry$processor = entry.processor) !== null && _entry$processor !== void 0 ? _entry$processor : options.processor) !== null && _ref2 !== void 0 ? _ref2 : "auto"
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
async function detectDefaultCssInput(root) {
|
|
177
|
+
const candidates = [
|
|
178
|
+
"src/styles.css",
|
|
179
|
+
"src/style.css",
|
|
180
|
+
"src/index.css",
|
|
181
|
+
"src/styles.scss",
|
|
182
|
+
"src/style.scss"
|
|
183
|
+
];
|
|
184
|
+
for (const candidate of candidates) try {
|
|
185
|
+
await node_fs_promises.default.access(node_path.default.resolve(root, candidate));
|
|
186
|
+
return candidate;
|
|
187
|
+
} catch {}
|
|
188
|
+
throw new Error(`[zeus-output-css] CSS input is required. Tried: ${candidates.join(", ")}`);
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
exports.default = css;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* output-css v0.1.0-beta.0
|
|
3
|
+
* (c) 2026 baicie
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
**/
|
|
6
|
+
Object.defineProperties(exports, {
|
|
7
|
+
__esModule: { value: true },
|
|
8
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
9
|
+
});
|
|
10
|
+
//#region \0rolldown/runtime.js
|
|
11
|
+
var __create = Object.create;
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
19
|
+
key = keys[i];
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
+
get: ((k) => from[k]).bind(null, key),
|
|
22
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
//#endregion
|
|
32
|
+
let node_fs_promises = require("node:fs/promises");
|
|
33
|
+
node_fs_promises = __toESM(node_fs_promises, 1);
|
|
34
|
+
let node_path = require("node:path");
|
|
35
|
+
node_path = __toESM(node_path, 1);
|
|
36
|
+
let node_module = require("node:module");
|
|
37
|
+
let node_url = require("node:url");
|
|
38
|
+
//#region packages/web-c/output-css/src/detect.ts
|
|
39
|
+
async function detectCssProcessor(input, root) {
|
|
40
|
+
const ext = node_path.default.extname(input).toLowerCase();
|
|
41
|
+
if (ext === ".scss" || ext === ".sass") return "sass";
|
|
42
|
+
if (ext === ".less") return "less";
|
|
43
|
+
if (ext === ".css") {
|
|
44
|
+
const rootDir = node_path.default.resolve(root);
|
|
45
|
+
if (await hasFile(node_path.default.join(rootDir, "postcss.config.js")) || await hasFile(node_path.default.join(rootDir, "postcss.config.cjs")) || await hasFile(node_path.default.join(rootDir, "postcss.config.mjs")) || await hasFile(node_path.default.join(rootDir, "postcss.config.ts")) || await hasFile(node_path.default.join(rootDir, "tailwind.config.js")) || await hasFile(node_path.default.join(rootDir, "tailwind.config.ts")) || await hasFile(node_path.default.join(rootDir, "tailwind.config.cjs")) || await hasFile(node_path.default.join(rootDir, "tailwind.config.mjs"))) return "postcss";
|
|
46
|
+
return "copy";
|
|
47
|
+
}
|
|
48
|
+
return "copy";
|
|
49
|
+
}
|
|
50
|
+
async function hasFile(file) {
|
|
51
|
+
try {
|
|
52
|
+
const { stat } = await import("node:fs/promises");
|
|
53
|
+
return (await stat(file)).isFile();
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region packages/web-c/output-css/src/processCss.ts
|
|
60
|
+
async function processCssEntry(entry, options, root) {
|
|
61
|
+
const input = node_path.default.resolve(root, entry.input);
|
|
62
|
+
const raw = await node_fs_promises.default.readFile(input, "utf-8");
|
|
63
|
+
const processor = entry.processor === "auto" ? await detectCssProcessor(input, root) : entry.processor;
|
|
64
|
+
let css = raw;
|
|
65
|
+
if (processor === "sass") css = await processSass(input);
|
|
66
|
+
else if (processor === "less") css = await processLess(input, raw);
|
|
67
|
+
else if (processor === "postcss") css = await processPostcss(input, raw, root);
|
|
68
|
+
if (options.minify) css = await minifyCss(input, css);
|
|
69
|
+
return { css };
|
|
70
|
+
}
|
|
71
|
+
async function processSass(input) {
|
|
72
|
+
let sass;
|
|
73
|
+
try {
|
|
74
|
+
sass = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("sass");
|
|
75
|
+
} catch {
|
|
76
|
+
throw new Error("[zeus-output-css] Install \"sass\" to process .scss/.sass files.");
|
|
77
|
+
}
|
|
78
|
+
return (await sass.compileStringAsync(await node_fs_promises.default.readFile(input, "utf-8"), {
|
|
79
|
+
url: (0, node_url.pathToFileURL)(input),
|
|
80
|
+
loadPaths: [node_path.default.dirname(input)]
|
|
81
|
+
})).css;
|
|
82
|
+
}
|
|
83
|
+
async function processLess(input, source) {
|
|
84
|
+
let less;
|
|
85
|
+
try {
|
|
86
|
+
less = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("less");
|
|
87
|
+
} catch {
|
|
88
|
+
throw new Error("[zeus-output-css] Install \"less\" to process .less files.");
|
|
89
|
+
}
|
|
90
|
+
return (await less.render(source, { filename: input })).css;
|
|
91
|
+
}
|
|
92
|
+
async function processPostcss(input, source, root) {
|
|
93
|
+
let postcss;
|
|
94
|
+
try {
|
|
95
|
+
postcss = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("postcss");
|
|
96
|
+
} catch {
|
|
97
|
+
throw new Error("[zeus-output-css] Install \"postcss\" to process CSS with PostCSS.");
|
|
98
|
+
}
|
|
99
|
+
let loadConfig;
|
|
100
|
+
try {
|
|
101
|
+
loadConfig = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("postcss-load-config");
|
|
102
|
+
} catch {
|
|
103
|
+
throw new Error("[zeus-output-css] Install \"postcss-load-config\" to load PostCSS config.");
|
|
104
|
+
}
|
|
105
|
+
const config = await loadConfig({}, root);
|
|
106
|
+
return (await postcss.default(config.plugins).process(source, {
|
|
107
|
+
from: input,
|
|
108
|
+
map: false
|
|
109
|
+
})).css;
|
|
110
|
+
}
|
|
111
|
+
async function minifyCss(_input, source) {
|
|
112
|
+
try {
|
|
113
|
+
let lightningcss;
|
|
114
|
+
lightningcss = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("lightningcss");
|
|
115
|
+
return lightningcss.transform({
|
|
116
|
+
filename: _input,
|
|
117
|
+
code: Buffer.from(source),
|
|
118
|
+
minify: true
|
|
119
|
+
}).code.toString();
|
|
120
|
+
} catch {
|
|
121
|
+
return source;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region packages/web-c/output-css/src/index.ts
|
|
126
|
+
function css(options = {}) {
|
|
127
|
+
const raw = typeof options === "string" ? { input: options } : options;
|
|
128
|
+
let normalized;
|
|
129
|
+
return {
|
|
130
|
+
name: "zeus-output-css",
|
|
131
|
+
async buildStart(ctx) {
|
|
132
|
+
normalized = await normalizeOptions(raw, ctx.root);
|
|
133
|
+
if (normalized.watch) for (const file of normalized.files) ctx.addWatchFile(node_path.default.resolve(ctx.root, file.input));
|
|
134
|
+
},
|
|
135
|
+
async generateBundle(ctx) {
|
|
136
|
+
var _normalized;
|
|
137
|
+
const current = (_normalized = normalized) !== null && _normalized !== void 0 ? _normalized : await normalizeOptions(raw, ctx.root);
|
|
138
|
+
const files = [];
|
|
139
|
+
for (const entry of current.files) {
|
|
140
|
+
const result = await processCssEntry(entry, current, ctx.root);
|
|
141
|
+
files.push({
|
|
142
|
+
type: "asset",
|
|
143
|
+
fileName: entry.fileName,
|
|
144
|
+
source: result.css
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return files;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
async function normalizeOptions(options, root) {
|
|
152
|
+
var _options$minify, _options$watch;
|
|
153
|
+
return {
|
|
154
|
+
files: await normalizeEntries(options, root),
|
|
155
|
+
minify: (_options$minify = options.minify) !== null && _options$minify !== void 0 ? _options$minify : false,
|
|
156
|
+
watch: (_options$watch = options.watch) !== null && _options$watch !== void 0 ? _options$watch : true
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
async function normalizeEntries(options, root) {
|
|
160
|
+
var _options$files, _options$input;
|
|
161
|
+
if ((_options$files = options.files) === null || _options$files === void 0 ? void 0 : _options$files.length) return options.files.map((file) => normalizeEntry(file, options));
|
|
162
|
+
return [normalizeEntry({
|
|
163
|
+
input: (_options$input = options.input) !== null && _options$input !== void 0 ? _options$input : await detectDefaultCssInput(root),
|
|
164
|
+
fileName: options.fileName,
|
|
165
|
+
processor: options.processor
|
|
166
|
+
}, options)];
|
|
167
|
+
}
|
|
168
|
+
function normalizeEntry(entry, options) {
|
|
169
|
+
var _ref, _entry$fileName, _ref2, _entry$processor;
|
|
170
|
+
return {
|
|
171
|
+
input: entry.input,
|
|
172
|
+
fileName: (_ref = (_entry$fileName = entry.fileName) !== null && _entry$fileName !== void 0 ? _entry$fileName : options.fileName) !== null && _ref !== void 0 ? _ref : "styles.css",
|
|
173
|
+
processor: (_ref2 = (_entry$processor = entry.processor) !== null && _entry$processor !== void 0 ? _entry$processor : options.processor) !== null && _ref2 !== void 0 ? _ref2 : "auto"
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
async function detectDefaultCssInput(root) {
|
|
177
|
+
const candidates = [
|
|
178
|
+
"src/styles.css",
|
|
179
|
+
"src/style.css",
|
|
180
|
+
"src/index.css",
|
|
181
|
+
"src/styles.scss",
|
|
182
|
+
"src/style.scss"
|
|
183
|
+
];
|
|
184
|
+
for (const candidate of candidates) try {
|
|
185
|
+
await node_fs_promises.default.access(node_path.default.resolve(root, candidate));
|
|
186
|
+
return candidate;
|
|
187
|
+
} catch {}
|
|
188
|
+
throw new Error(`[zeus-output-css] CSS input is required. Tried: ${candidates.join(", ")}`);
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
exports.default = css;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ZeusComponentPlugin } from '@zeus-js/bundler-plugin';
|
|
2
|
+
|
|
3
|
+
export type CssProcessor = 'auto' | 'copy' | 'postcss' | 'sass' | 'less';
|
|
4
|
+
export interface OutputCssOptions {
|
|
5
|
+
/**
|
|
6
|
+
* CSS input file.
|
|
7
|
+
*
|
|
8
|
+
* @default auto-detect:
|
|
9
|
+
* - src/styles.css
|
|
10
|
+
* - src/style.css
|
|
11
|
+
* - src/index.css
|
|
12
|
+
* - src/styles.scss
|
|
13
|
+
* - src/style.scss
|
|
14
|
+
*/
|
|
15
|
+
input?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Output CSS file name.
|
|
18
|
+
*
|
|
19
|
+
* @default 'styles.css'
|
|
20
|
+
*/
|
|
21
|
+
fileName?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Multiple CSS entries.
|
|
24
|
+
*/
|
|
25
|
+
files?: CssEntry[];
|
|
26
|
+
/**
|
|
27
|
+
* CSS processor.
|
|
28
|
+
*
|
|
29
|
+
* @default 'auto'
|
|
30
|
+
*/
|
|
31
|
+
processor?: CssProcessor;
|
|
32
|
+
/**
|
|
33
|
+
* Minify CSS.
|
|
34
|
+
*
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
minify?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Add CSS file to watch list.
|
|
40
|
+
*
|
|
41
|
+
* @default true
|
|
42
|
+
*/
|
|
43
|
+
watch?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface CssEntry {
|
|
46
|
+
input: string;
|
|
47
|
+
fileName?: string;
|
|
48
|
+
processor?: CssProcessor;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export declare function css(options?: OutputCssOptions | string): ZeusComponentPlugin;
|
|
52
|
+
|
|
53
|
+
export { css as default };
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* output-css v0.1.0-beta.0
|
|
3
|
+
* (c) 2026 baicie
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
**/
|
|
6
|
+
import fs from "node:fs/promises";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { createRequire } from "node:module";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/asyncToGenerator.js
|
|
11
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
12
|
+
try {
|
|
13
|
+
var i = n[a](c), u = i.value;
|
|
14
|
+
} catch (n) {
|
|
15
|
+
e(n);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
19
|
+
}
|
|
20
|
+
function _asyncToGenerator(n) {
|
|
21
|
+
return function() {
|
|
22
|
+
var t = this, e = arguments;
|
|
23
|
+
return new Promise(function(r, o) {
|
|
24
|
+
var a = n.apply(t, e);
|
|
25
|
+
function _next(n) {
|
|
26
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
27
|
+
}
|
|
28
|
+
function _throw(n) {
|
|
29
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
30
|
+
}
|
|
31
|
+
_next(void 0);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region packages/web-c/output-css/src/detect.ts
|
|
37
|
+
function detectCssProcessor(_x, _x2) {
|
|
38
|
+
return _detectCssProcessor.apply(this, arguments);
|
|
39
|
+
}
|
|
40
|
+
function _detectCssProcessor() {
|
|
41
|
+
_detectCssProcessor = _asyncToGenerator(function* (input, root) {
|
|
42
|
+
const ext = path.extname(input).toLowerCase();
|
|
43
|
+
if (ext === ".scss" || ext === ".sass") return "sass";
|
|
44
|
+
if (ext === ".less") return "less";
|
|
45
|
+
if (ext === ".css") {
|
|
46
|
+
const rootDir = path.resolve(root);
|
|
47
|
+
if ((yield hasFile(path.join(rootDir, "postcss.config.js"))) || (yield hasFile(path.join(rootDir, "postcss.config.cjs"))) || (yield hasFile(path.join(rootDir, "postcss.config.mjs"))) || (yield hasFile(path.join(rootDir, "postcss.config.ts"))) || (yield hasFile(path.join(rootDir, "tailwind.config.js"))) || (yield hasFile(path.join(rootDir, "tailwind.config.ts"))) || (yield hasFile(path.join(rootDir, "tailwind.config.cjs"))) || (yield hasFile(path.join(rootDir, "tailwind.config.mjs")))) return "postcss";
|
|
48
|
+
return "copy";
|
|
49
|
+
}
|
|
50
|
+
return "copy";
|
|
51
|
+
});
|
|
52
|
+
return _detectCssProcessor.apply(this, arguments);
|
|
53
|
+
}
|
|
54
|
+
function hasFile(_x3) {
|
|
55
|
+
return _hasFile.apply(this, arguments);
|
|
56
|
+
}
|
|
57
|
+
function _hasFile() {
|
|
58
|
+
_hasFile = _asyncToGenerator(function* (file) {
|
|
59
|
+
try {
|
|
60
|
+
const { stat } = yield import("node:fs/promises");
|
|
61
|
+
return (yield stat(file)).isFile();
|
|
62
|
+
} catch (_unused) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return _hasFile.apply(this, arguments);
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region packages/web-c/output-css/src/processCss.ts
|
|
70
|
+
function processCssEntry(_x, _x2, _x3) {
|
|
71
|
+
return _processCssEntry.apply(this, arguments);
|
|
72
|
+
}
|
|
73
|
+
function _processCssEntry() {
|
|
74
|
+
_processCssEntry = _asyncToGenerator(function* (entry, options, root) {
|
|
75
|
+
const input = path.resolve(root, entry.input);
|
|
76
|
+
const raw = yield fs.readFile(input, "utf-8");
|
|
77
|
+
const processor = entry.processor === "auto" ? yield detectCssProcessor(input, root) : entry.processor;
|
|
78
|
+
let css = raw;
|
|
79
|
+
if (processor === "sass") css = yield processSass(input);
|
|
80
|
+
else if (processor === "less") css = yield processLess(input, raw);
|
|
81
|
+
else if (processor === "postcss") css = yield processPostcss(input, raw, root);
|
|
82
|
+
if (options.minify) css = yield minifyCss(input, css);
|
|
83
|
+
return { css };
|
|
84
|
+
});
|
|
85
|
+
return _processCssEntry.apply(this, arguments);
|
|
86
|
+
}
|
|
87
|
+
function processSass(_x4) {
|
|
88
|
+
return _processSass.apply(this, arguments);
|
|
89
|
+
}
|
|
90
|
+
function _processSass() {
|
|
91
|
+
_processSass = _asyncToGenerator(function* (input) {
|
|
92
|
+
let sass;
|
|
93
|
+
try {
|
|
94
|
+
sass = createRequire(import.meta.url)("sass");
|
|
95
|
+
} catch (_unused) {
|
|
96
|
+
throw new Error("[zeus-output-css] Install \"sass\" to process .scss/.sass files.");
|
|
97
|
+
}
|
|
98
|
+
return (yield sass.compileStringAsync(yield fs.readFile(input, "utf-8"), {
|
|
99
|
+
url: pathToFileURL(input),
|
|
100
|
+
loadPaths: [path.dirname(input)]
|
|
101
|
+
})).css;
|
|
102
|
+
});
|
|
103
|
+
return _processSass.apply(this, arguments);
|
|
104
|
+
}
|
|
105
|
+
function processLess(_x5, _x6) {
|
|
106
|
+
return _processLess.apply(this, arguments);
|
|
107
|
+
}
|
|
108
|
+
function _processLess() {
|
|
109
|
+
_processLess = _asyncToGenerator(function* (input, source) {
|
|
110
|
+
let less;
|
|
111
|
+
try {
|
|
112
|
+
less = createRequire(import.meta.url)("less");
|
|
113
|
+
} catch (_unused2) {
|
|
114
|
+
throw new Error("[zeus-output-css] Install \"less\" to process .less files.");
|
|
115
|
+
}
|
|
116
|
+
return (yield less.render(source, { filename: input })).css;
|
|
117
|
+
});
|
|
118
|
+
return _processLess.apply(this, arguments);
|
|
119
|
+
}
|
|
120
|
+
function processPostcss(_x7, _x8, _x9) {
|
|
121
|
+
return _processPostcss.apply(this, arguments);
|
|
122
|
+
}
|
|
123
|
+
function _processPostcss() {
|
|
124
|
+
_processPostcss = _asyncToGenerator(function* (input, source, root) {
|
|
125
|
+
let postcss;
|
|
126
|
+
try {
|
|
127
|
+
postcss = createRequire(import.meta.url)("postcss");
|
|
128
|
+
} catch (_unused3) {
|
|
129
|
+
throw new Error("[zeus-output-css] Install \"postcss\" to process CSS with PostCSS.");
|
|
130
|
+
}
|
|
131
|
+
let loadConfig;
|
|
132
|
+
try {
|
|
133
|
+
loadConfig = createRequire(import.meta.url)("postcss-load-config");
|
|
134
|
+
} catch (_unused4) {
|
|
135
|
+
throw new Error("[zeus-output-css] Install \"postcss-load-config\" to load PostCSS config.");
|
|
136
|
+
}
|
|
137
|
+
const config = yield loadConfig({}, root);
|
|
138
|
+
return (yield postcss.default(config.plugins).process(source, {
|
|
139
|
+
from: input,
|
|
140
|
+
map: false
|
|
141
|
+
})).css;
|
|
142
|
+
});
|
|
143
|
+
return _processPostcss.apply(this, arguments);
|
|
144
|
+
}
|
|
145
|
+
function minifyCss(_x10, _x11) {
|
|
146
|
+
return _minifyCss.apply(this, arguments);
|
|
147
|
+
}
|
|
148
|
+
function _minifyCss() {
|
|
149
|
+
_minifyCss = _asyncToGenerator(function* (_input, source) {
|
|
150
|
+
try {
|
|
151
|
+
let lightningcss;
|
|
152
|
+
lightningcss = createRequire(import.meta.url)("lightningcss");
|
|
153
|
+
return lightningcss.transform({
|
|
154
|
+
filename: _input,
|
|
155
|
+
code: Buffer.from(source),
|
|
156
|
+
minify: true
|
|
157
|
+
}).code.toString();
|
|
158
|
+
} catch (_unused5) {
|
|
159
|
+
return source;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return _minifyCss.apply(this, arguments);
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region packages/web-c/output-css/src/index.ts
|
|
166
|
+
function css(options = {}) {
|
|
167
|
+
const raw = typeof options === "string" ? { input: options } : options;
|
|
168
|
+
let normalized;
|
|
169
|
+
return {
|
|
170
|
+
name: "zeus-output-css",
|
|
171
|
+
buildStart(ctx) {
|
|
172
|
+
return _asyncToGenerator(function* () {
|
|
173
|
+
normalized = yield normalizeOptions(raw, ctx.root);
|
|
174
|
+
if (normalized.watch) for (const file of normalized.files) ctx.addWatchFile(path.resolve(ctx.root, file.input));
|
|
175
|
+
})();
|
|
176
|
+
},
|
|
177
|
+
generateBundle(ctx) {
|
|
178
|
+
return _asyncToGenerator(function* () {
|
|
179
|
+
var _normalized;
|
|
180
|
+
const current = (_normalized = normalized) !== null && _normalized !== void 0 ? _normalized : yield normalizeOptions(raw, ctx.root);
|
|
181
|
+
const files = [];
|
|
182
|
+
for (const entry of current.files) {
|
|
183
|
+
const result = yield processCssEntry(entry, current, ctx.root);
|
|
184
|
+
files.push({
|
|
185
|
+
type: "asset",
|
|
186
|
+
fileName: entry.fileName,
|
|
187
|
+
source: result.css
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return files;
|
|
191
|
+
})();
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function normalizeOptions(_x, _x2) {
|
|
196
|
+
return _normalizeOptions.apply(this, arguments);
|
|
197
|
+
}
|
|
198
|
+
function _normalizeOptions() {
|
|
199
|
+
_normalizeOptions = _asyncToGenerator(function* (options, root) {
|
|
200
|
+
var _options$minify, _options$watch;
|
|
201
|
+
return {
|
|
202
|
+
files: yield normalizeEntries(options, root),
|
|
203
|
+
minify: (_options$minify = options.minify) !== null && _options$minify !== void 0 ? _options$minify : false,
|
|
204
|
+
watch: (_options$watch = options.watch) !== null && _options$watch !== void 0 ? _options$watch : true
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
return _normalizeOptions.apply(this, arguments);
|
|
208
|
+
}
|
|
209
|
+
function normalizeEntries(_x3, _x4) {
|
|
210
|
+
return _normalizeEntries.apply(this, arguments);
|
|
211
|
+
}
|
|
212
|
+
function _normalizeEntries() {
|
|
213
|
+
_normalizeEntries = _asyncToGenerator(function* (options, root) {
|
|
214
|
+
var _options$files, _options$input;
|
|
215
|
+
if ((_options$files = options.files) === null || _options$files === void 0 ? void 0 : _options$files.length) return options.files.map((file) => normalizeEntry(file, options));
|
|
216
|
+
return [normalizeEntry({
|
|
217
|
+
input: (_options$input = options.input) !== null && _options$input !== void 0 ? _options$input : yield detectDefaultCssInput(root),
|
|
218
|
+
fileName: options.fileName,
|
|
219
|
+
processor: options.processor
|
|
220
|
+
}, options)];
|
|
221
|
+
});
|
|
222
|
+
return _normalizeEntries.apply(this, arguments);
|
|
223
|
+
}
|
|
224
|
+
function normalizeEntry(entry, options) {
|
|
225
|
+
var _ref, _entry$fileName, _ref2, _entry$processor;
|
|
226
|
+
return {
|
|
227
|
+
input: entry.input,
|
|
228
|
+
fileName: (_ref = (_entry$fileName = entry.fileName) !== null && _entry$fileName !== void 0 ? _entry$fileName : options.fileName) !== null && _ref !== void 0 ? _ref : "styles.css",
|
|
229
|
+
processor: (_ref2 = (_entry$processor = entry.processor) !== null && _entry$processor !== void 0 ? _entry$processor : options.processor) !== null && _ref2 !== void 0 ? _ref2 : "auto"
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function detectDefaultCssInput(_x5) {
|
|
233
|
+
return _detectDefaultCssInput.apply(this, arguments);
|
|
234
|
+
}
|
|
235
|
+
function _detectDefaultCssInput() {
|
|
236
|
+
_detectDefaultCssInput = _asyncToGenerator(function* (root) {
|
|
237
|
+
const candidates = [
|
|
238
|
+
"src/styles.css",
|
|
239
|
+
"src/style.css",
|
|
240
|
+
"src/index.css",
|
|
241
|
+
"src/styles.scss",
|
|
242
|
+
"src/style.scss"
|
|
243
|
+
];
|
|
244
|
+
for (const candidate of candidates) try {
|
|
245
|
+
yield fs.access(path.resolve(root, candidate));
|
|
246
|
+
return candidate;
|
|
247
|
+
} catch (_unused) {}
|
|
248
|
+
throw new Error(`[zeus-output-css] CSS input is required. Tried: ${candidates.join(", ")}`);
|
|
249
|
+
});
|
|
250
|
+
return _detectDefaultCssInput.apply(this, arguments);
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
export { css as default };
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zeus-js/output-css",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "Zeus CSS asset output plugin",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"module": "dist/output-css.esm-bundler.js",
|
|
8
|
+
"types": "dist/output-css.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js",
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/output-css.d.ts",
|
|
16
|
+
"node": {
|
|
17
|
+
"production": "./dist/output-css.cjs.prod.js",
|
|
18
|
+
"development": "./dist/output-css.cjs.js",
|
|
19
|
+
"default": "./index.js"
|
|
20
|
+
},
|
|
21
|
+
"module": "./dist/output-css.esm-bundler.js",
|
|
22
|
+
"import": "./dist/output-css.esm-bundler.js",
|
|
23
|
+
"require": "./index.js"
|
|
24
|
+
},
|
|
25
|
+
"./*": "./*"
|
|
26
|
+
},
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/baicie/zeus"
|
|
31
|
+
},
|
|
32
|
+
"buildOptions": {
|
|
33
|
+
"name": "ZeusOutputCSS",
|
|
34
|
+
"formats": [
|
|
35
|
+
"esm-bundler",
|
|
36
|
+
"cjs"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"lightningcss": "^1.29.0",
|
|
41
|
+
"postcss": "*",
|
|
42
|
+
"postcss-load-config": "*",
|
|
43
|
+
"rollup": "^4.0.0",
|
|
44
|
+
"sass": "*",
|
|
45
|
+
"less": "*"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"lightningcss": {
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"postcss": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"postcss-load-config": {
|
|
55
|
+
"optional": true
|
|
56
|
+
},
|
|
57
|
+
"rollup": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"sass": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"less": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"keywords": [
|
|
68
|
+
"zeus",
|
|
69
|
+
"css"
|
|
70
|
+
],
|
|
71
|
+
"author": "Baicie",
|
|
72
|
+
"license": "MIT"
|
|
73
|
+
}
|