carbon-preprocess-svelte 0.11.1 → 0.11.3
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/plugins/OptimizeCssPlugin.js +3 -3
- package/dist/plugins/create-optimized-css.d.ts +6 -1
- package/dist/plugins/create-optimized-css.js +4 -7
- package/dist/plugins/optimize-css.js +3 -3
- package/dist/plugins/{compare-diff.d.ts → print-diff.d.ts} +1 -1
- package/dist/plugins/{compare-diff.js → print-diff.js} +6 -3
- package/dist/preprocessors/optimize-imports.js +2 -1
- package/package.json +5 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
|
-
const compare_diff_1 = require("./compare-diff");
|
|
5
4
|
const create_optimized_css_1 = require("./create-optimized-css");
|
|
5
|
+
const print_diff_1 = require("./print-diff");
|
|
6
6
|
// Webpack plugin to optimize CSS for Carbon Svelte components.
|
|
7
7
|
class OptimizeCssPlugin {
|
|
8
8
|
constructor(options) {
|
|
@@ -35,10 +35,10 @@ class OptimizeCssPlugin {
|
|
|
35
35
|
for (const [id] of Object.entries(assets)) {
|
|
36
36
|
if ((0, utils_1.isCssFile)(id)) {
|
|
37
37
|
const original_css = assets[id].source();
|
|
38
|
-
const optimized_css = (0, create_optimized_css_1.createOptimizedCss)(
|
|
38
|
+
const optimized_css = (0, create_optimized_css_1.createOptimizedCss)(Object.assign(Object.assign({}, this.options), { source: original_css, ids }));
|
|
39
39
|
compilation.updateAsset(id, new RawSource(optimized_css));
|
|
40
40
|
if (this.options.verbose) {
|
|
41
|
-
(0,
|
|
41
|
+
(0, print_diff_1.printDiff)({ original_css, optimized_css, id });
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -22,4 +22,9 @@ export type OptimizeCssOptions = {
|
|
|
22
22
|
*/
|
|
23
23
|
preserveAllIBMFonts?: boolean;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
type CreateOptimizedCssOptions = OptimizeCssOptions & {
|
|
26
|
+
source: Uint8Array | string;
|
|
27
|
+
ids: string[];
|
|
28
|
+
};
|
|
29
|
+
export declare function createOptimizedCss(options: CreateOptimizedCssOptions): string;
|
|
30
|
+
export {};
|
|
@@ -9,7 +9,8 @@ const postcss_1 = __importDefault(require("postcss"));
|
|
|
9
9
|
const postcss_discard_empty_1 = __importDefault(require("postcss-discard-empty"));
|
|
10
10
|
const component_index_1 = require("../component-index");
|
|
11
11
|
const constants_1 = require("../constants");
|
|
12
|
-
function createOptimizedCss(
|
|
12
|
+
function createOptimizedCss(options) {
|
|
13
|
+
const { source, ids } = options;
|
|
13
14
|
const preserveAllIBMFonts = (options === null || options === void 0 ? void 0 : options.preserveAllIBMFonts) === true;
|
|
14
15
|
// List of Carbon classes that must be preserved in the CSS
|
|
15
16
|
// but that are not referenced in Carbon Svelte components.
|
|
@@ -62,13 +63,9 @@ function createOptimizedCss(original_css, ids, options) {
|
|
|
62
63
|
node.walkDecls((decl) => {
|
|
63
64
|
switch (decl.prop) {
|
|
64
65
|
case "font-family":
|
|
65
|
-
attributes["font-family"] = decl.value;
|
|
66
|
-
break;
|
|
67
66
|
case "font-style":
|
|
68
|
-
attributes["font-style"] = decl.value;
|
|
69
|
-
break;
|
|
70
67
|
case "font-weight":
|
|
71
|
-
attributes[
|
|
68
|
+
attributes[decl.prop] = decl.value;
|
|
72
69
|
break;
|
|
73
70
|
}
|
|
74
71
|
});
|
|
@@ -85,6 +82,6 @@ function createOptimizedCss(original_css, ids, options) {
|
|
|
85
82
|
},
|
|
86
83
|
},
|
|
87
84
|
(0, postcss_discard_empty_1.default)(),
|
|
88
|
-
]).process(
|
|
85
|
+
]).process(source).css;
|
|
89
86
|
}
|
|
90
87
|
exports.createOptimizedCss = createOptimizedCss;
|
|
@@ -11,8 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.optimizeCss = void 0;
|
|
13
13
|
const utils_1 = require("../utils");
|
|
14
|
-
const compare_diff_1 = require("./compare-diff");
|
|
15
14
|
const create_optimized_css_1 = require("./create-optimized-css");
|
|
15
|
+
const print_diff_1 = require("./print-diff");
|
|
16
16
|
// Vite plugin (Rollup-compatible) to optimize CSS for Carbon Svelte components.
|
|
17
17
|
const optimizeCss = (options) => {
|
|
18
18
|
const verbose = (options === null || options === void 0 ? void 0 : options.verbose) !== false;
|
|
@@ -35,10 +35,10 @@ const optimizeCss = (options) => {
|
|
|
35
35
|
const file = bundle[id];
|
|
36
36
|
if (file.type === "asset" && (0, utils_1.isCssFile)(id)) {
|
|
37
37
|
const original_css = file.source;
|
|
38
|
-
const optimized_css = (0, create_optimized_css_1.createOptimizedCss)(original_css, ids
|
|
38
|
+
const optimized_css = (0, create_optimized_css_1.createOptimizedCss)(Object.assign(Object.assign({}, options), { source: original_css, ids }));
|
|
39
39
|
file.source = optimized_css;
|
|
40
40
|
if (verbose) {
|
|
41
|
-
(0,
|
|
41
|
+
(0, print_diff_1.printDiff)({ original_css, optimized_css, id });
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.printDiff = void 0;
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
5
|
const formatter = new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 });
|
|
6
6
|
function toHumanReadableSize(size_in_kb) {
|
|
@@ -19,10 +19,13 @@ function stringSizeInKB(str) {
|
|
|
19
19
|
function padIfNeeded(a, b) {
|
|
20
20
|
return a.length > b.length ? a : a.padStart(b.length, " ");
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function printDiff(props) {
|
|
23
23
|
const { original_css, optimized_css, id } = props;
|
|
24
24
|
const original_size = stringSizeInKB(original_css.toString());
|
|
25
25
|
const optimized_size = stringSizeInKB(optimized_css);
|
|
26
|
+
if (original_size === optimized_size) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
26
29
|
const original = toHumanReadableSize(original_size);
|
|
27
30
|
const optimized = toHumanReadableSize(optimized_size);
|
|
28
31
|
const original_display = padIfNeeded(original, optimized);
|
|
@@ -33,4 +36,4 @@ function compareDiff(props) {
|
|
|
33
36
|
console.log("Before:", original_display);
|
|
34
37
|
console.log("After: ", optimized_display, `(-${diff})\n`);
|
|
35
38
|
}
|
|
36
|
-
exports.
|
|
39
|
+
exports.printDiff = printDiff;
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.optimizeImports = void 0;
|
|
7
|
+
const estree_walker_1 = require("estree-walker");
|
|
7
8
|
const magic_string_1 = __importDefault(require("magic-string"));
|
|
8
9
|
const compiler_1 = require("svelte/compiler");
|
|
9
10
|
const component_index_1 = require("../component-index");
|
|
@@ -29,7 +30,7 @@ const optimizeImports = () => {
|
|
|
29
30
|
// Wrap the content in a `<script>` tag to parse it with the Svelte parser.
|
|
30
31
|
const content = `<script>${raw}</script>`;
|
|
31
32
|
const s = new magic_string_1.default(content);
|
|
32
|
-
(0,
|
|
33
|
+
(0, estree_walker_1.walk)((0, compiler_1.parse)(content), {
|
|
33
34
|
enter(node) {
|
|
34
35
|
if (node.type === "ImportDeclaration") {
|
|
35
36
|
const import_name = node.source.value;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbon-preprocess-svelte",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Svelte preprocessors for the Carbon Design System",
|
|
6
6
|
"author": "Eric Liu (https://github.com/metonym)",
|
|
@@ -8,16 +8,18 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"index:components": "bun scripts/index-components.ts",
|
|
11
|
-
"
|
|
12
|
-
"format": "
|
|
11
|
+
"build": "bun --bun tsc -p tsconfig.build.json",
|
|
12
|
+
"format": "bun --bun prettier --write . --cache"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"estree-walker": "^2.0.2",
|
|
15
16
|
"magic-string": "^0.30.8",
|
|
16
17
|
"postcss": "^8.4.36",
|
|
17
18
|
"postcss-discard-empty": "^6.0.3"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"@types/bun": "latest",
|
|
22
|
+
"@types/jest": "latest",
|
|
21
23
|
"carbon-components-svelte": "0.85.0",
|
|
22
24
|
"prettier": "latest",
|
|
23
25
|
"svelte": "latest",
|