@bamboocss/plugin-lightningcss 1.11.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.md +16 -0
- package/dist/index.js +80 -0
- package/dist/index.mjs +42 -0
- package/package.json +46 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Segun Adebayo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
6
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
7
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
11
|
+
Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
14
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
15
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
16
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
optimizeLightCss: () => optimizeLightCss,
|
|
34
|
+
pluginLightningcss: () => pluginLightningcss
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// src/optimize-lightningcss.ts
|
|
39
|
+
var import_logger = require("@bamboocss/logger");
|
|
40
|
+
var import_lightningcss = require("lightningcss");
|
|
41
|
+
var import_browserslist = __toESM(require("browserslist"));
|
|
42
|
+
var decoder = new TextDecoder();
|
|
43
|
+
function optimizeLightCss(code, options = {}) {
|
|
44
|
+
const { minify = false, browserslist: targets } = options;
|
|
45
|
+
const result = (0, import_lightningcss.transform)({
|
|
46
|
+
// https://stackoverflow.com/questions/78790943/in-typescript-5-6-buffer-is-not-assignable-to-arraybufferview-or-uint8arr
|
|
47
|
+
code: Buffer.from(code),
|
|
48
|
+
minify,
|
|
49
|
+
sourceMap: false,
|
|
50
|
+
filename: "styles.css",
|
|
51
|
+
include: import_lightningcss.Features.Nesting | import_lightningcss.Features.MediaRangeSyntax,
|
|
52
|
+
targets: (0, import_lightningcss.browserslistToTargets)((0, import_browserslist.default)(targets)),
|
|
53
|
+
errorRecovery: true
|
|
54
|
+
});
|
|
55
|
+
if (result.warnings.length) {
|
|
56
|
+
const split = code.split("\n");
|
|
57
|
+
import_logger.logger.warn(
|
|
58
|
+
"css",
|
|
59
|
+
result.warnings.map((w) => ({ ...w, line: split[w.loc.line - 1] }))
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return decoder.decode(result.code);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/index.ts
|
|
66
|
+
function pluginLightningcss() {
|
|
67
|
+
return {
|
|
68
|
+
name: "@bamboocss/plugin-lightningcss",
|
|
69
|
+
hooks: {
|
|
70
|
+
"css:optimize": ({ css, minify, browserslist: browserslist2 }) => {
|
|
71
|
+
return optimizeLightCss(css, { minify, browserslist: browserslist2 });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
optimizeLightCss,
|
|
79
|
+
pluginLightningcss
|
|
80
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/optimize-lightningcss.ts
|
|
2
|
+
import { logger } from "@bamboocss/logger";
|
|
3
|
+
import { Features, transform, browserslistToTargets } from "lightningcss";
|
|
4
|
+
import browserslist from "browserslist";
|
|
5
|
+
var decoder = new TextDecoder();
|
|
6
|
+
function optimizeLightCss(code, options = {}) {
|
|
7
|
+
const { minify = false, browserslist: targets } = options;
|
|
8
|
+
const result = transform({
|
|
9
|
+
// https://stackoverflow.com/questions/78790943/in-typescript-5-6-buffer-is-not-assignable-to-arraybufferview-or-uint8arr
|
|
10
|
+
code: Buffer.from(code),
|
|
11
|
+
minify,
|
|
12
|
+
sourceMap: false,
|
|
13
|
+
filename: "styles.css",
|
|
14
|
+
include: Features.Nesting | Features.MediaRangeSyntax,
|
|
15
|
+
targets: browserslistToTargets(browserslist(targets)),
|
|
16
|
+
errorRecovery: true
|
|
17
|
+
});
|
|
18
|
+
if (result.warnings.length) {
|
|
19
|
+
const split = code.split("\n");
|
|
20
|
+
logger.warn(
|
|
21
|
+
"css",
|
|
22
|
+
result.warnings.map((w) => ({ ...w, line: split[w.loc.line - 1] }))
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return decoder.decode(result.code);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/index.ts
|
|
29
|
+
function pluginLightningcss() {
|
|
30
|
+
return {
|
|
31
|
+
name: "@bamboocss/plugin-lightningcss",
|
|
32
|
+
hooks: {
|
|
33
|
+
"css:optimize": ({ css, minify, browserslist: browserslist2 }) => {
|
|
34
|
+
return optimizeLightCss(css, { minify, browserslist: browserslist2 });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
optimizeLightCss,
|
|
41
|
+
pluginLightningcss
|
|
42
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bamboocss/plugin-lightningcss",
|
|
3
|
+
"version": "1.11.1",
|
|
4
|
+
"description": "Bamboo CSS plugin for LightningCSS optimization",
|
|
5
|
+
"homepage": "https://bamboo-css.com",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Segun Adebayo <joseshegs@gmail.com>",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/chakra-ui/bamboo.git",
|
|
11
|
+
"directory": "packages/plugin-lightningcss"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"module": "dist/index.mjs",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"source": "./src/index.ts",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"require": "./dist/index.js",
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"browserslist": "4.28.1",
|
|
37
|
+
"lightningcss": "1.31.1",
|
|
38
|
+
"@bamboocss/logger": "1.11.1",
|
|
39
|
+
"@bamboocss/types": "1.11.1"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup src/index.ts --format=esm,cjs --dts",
|
|
43
|
+
"build-fast": "tsup src/index.ts --format=esm,cjs --no-dts",
|
|
44
|
+
"dev": "pnpm build-fast --watch"
|
|
45
|
+
}
|
|
46
|
+
}
|