carbon-preprocess-svelte 0.11.4 → 0.11.6
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 +32 -30
- package/dist/component-index.js +1 -1921
- package/dist/constants.js +0 -1
- package/dist/plugins/OptimizeCssPlugin.js +0 -2
- package/dist/plugins/create-optimized-css.d.ts +0 -20
- package/dist/plugins/create-optimized-css.js +0 -9
- package/dist/plugins/optimize-css.js +0 -2
- package/dist/preprocessors/optimize-imports.js +3 -5
- package/dist/utils.js +1 -1
- package/package.json +5 -25
package/dist/constants.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
4
|
const create_optimized_css_1 = require("./create-optimized-css");
|
|
5
5
|
const print_diff_1 = require("./print-diff");
|
|
6
|
-
// Webpack plugin to optimize CSS for Carbon Svelte components.
|
|
7
6
|
class OptimizeCssPlugin {
|
|
8
7
|
constructor(options) {
|
|
9
8
|
this.options = {
|
|
@@ -29,7 +28,6 @@ class OptimizeCssPlugin {
|
|
|
29
28
|
name: OptimizeCssPlugin.name,
|
|
30
29
|
stage: Compilation.PROCESS_ASSETS_STAGE_DERIVED,
|
|
31
30
|
}, (assets) => {
|
|
32
|
-
// Skip processing if no Carbon Svelte imports are found.
|
|
33
31
|
if (ids.length === 0)
|
|
34
32
|
return;
|
|
35
33
|
for (const [id] of Object.entries(assets)) {
|
|
@@ -1,25 +1,5 @@
|
|
|
1
1
|
export type OptimizeCssOptions = {
|
|
2
|
-
/**
|
|
3
|
-
* By default, the plugin will print the size
|
|
4
|
-
* difference between the original and optimized CSS.
|
|
5
|
-
*
|
|
6
|
-
* Set to `false` to disable verbose logging.
|
|
7
|
-
* @default true
|
|
8
|
-
*/
|
|
9
2
|
verbose?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* By default, pre-compiled Carbon StyleSheets ship `@font-face` rules
|
|
12
|
-
* for all available IBM Plex fonts, many of which are not actually
|
|
13
|
-
* used in Carbon Svelte components.
|
|
14
|
-
*
|
|
15
|
-
* The default behavior is to preserve the following IBM Plex fonts:
|
|
16
|
-
* - IBM Plex Sans (300/400/600-weight and normal-font-style rules)
|
|
17
|
-
* - IBM Plex Mono (400-weight and normal-font-style rules)
|
|
18
|
-
*
|
|
19
|
-
* Set to `true` to disable this behavior and
|
|
20
|
-
* retain *all* IBM Plex `@font-face` rules.
|
|
21
|
-
* @default false
|
|
22
|
-
*/
|
|
23
3
|
preserveAllIBMFonts?: boolean;
|
|
24
4
|
};
|
|
25
5
|
type CreateOptimizedCssOptions = OptimizeCssOptions & {
|
|
@@ -12,8 +12,6 @@ const constants_1 = require("../constants");
|
|
|
12
12
|
function createOptimizedCss(options) {
|
|
13
13
|
const { source, ids } = options;
|
|
14
14
|
const preserveAllIBMFonts = (options === null || options === void 0 ? void 0 : options.preserveAllIBMFonts) === true;
|
|
15
|
-
// List of Carbon classes that must be preserved in the CSS
|
|
16
|
-
// but that are not referenced in Carbon Svelte components.
|
|
17
15
|
const css_allowlist = [".bx--body"];
|
|
18
16
|
for (const id of ids) {
|
|
19
17
|
const { name } = node_path_1.default.parse(id);
|
|
@@ -26,22 +24,16 @@ function createOptimizedCss(options) {
|
|
|
26
24
|
postcssPlugin: "postcss-plugin:carbon:optimize-css",
|
|
27
25
|
Rule(node) {
|
|
28
26
|
const selector = node.selector;
|
|
29
|
-
// Ensure that the selector contains a Carbon prefix.
|
|
30
27
|
if (constants_1.CARBON_PREFIX.test(selector)) {
|
|
31
|
-
// Selectors may contain multiple classes, separated by a comma.
|
|
32
28
|
const classes = selector.split(",").filter((selectee) => {
|
|
33
29
|
var _a;
|
|
34
30
|
const value = (_a = selectee.trim()) !== null && _a !== void 0 ? _a : "";
|
|
35
|
-
// Some Carbon classes are prefixed with a tag for higher specificity.
|
|
36
|
-
// E.g., a.bx--header
|
|
37
31
|
const [, rest] = value.split(".");
|
|
38
32
|
return Boolean(rest);
|
|
39
33
|
});
|
|
40
34
|
let remove_rule = true;
|
|
41
35
|
for (const name of classes) {
|
|
42
36
|
for (const selector of css_allowlist) {
|
|
43
|
-
// If at least one class is in the allowlist, keep the rule.
|
|
44
|
-
// This is a simplistic approach and can be further optimized.
|
|
45
37
|
if (name.includes(selector)) {
|
|
46
38
|
remove_rule = false;
|
|
47
39
|
break;
|
|
@@ -69,7 +61,6 @@ function createOptimizedCss(options) {
|
|
|
69
61
|
break;
|
|
70
62
|
}
|
|
71
63
|
});
|
|
72
|
-
// Do not proceed if font is not IBM Plex.
|
|
73
64
|
if (!attributes["font-family"].startsWith("IBM Plex")) {
|
|
74
65
|
return;
|
|
75
66
|
}
|
|
@@ -13,7 +13,6 @@ exports.optimizeCss = void 0;
|
|
|
13
13
|
const utils_1 = require("../utils");
|
|
14
14
|
const create_optimized_css_1 = require("./create-optimized-css");
|
|
15
15
|
const print_diff_1 = require("./print-diff");
|
|
16
|
-
// Vite plugin (Rollup-compatible) to optimize CSS for Carbon Svelte components.
|
|
17
16
|
const optimizeCss = (options) => {
|
|
18
17
|
const verbose = (options === null || options === void 0 ? void 0 : options.verbose) !== false;
|
|
19
18
|
const ids = [];
|
|
@@ -28,7 +27,6 @@ const optimizeCss = (options) => {
|
|
|
28
27
|
},
|
|
29
28
|
generateBundle(_, bundle) {
|
|
30
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
// Skip processing if no Carbon Svelte imports are found.
|
|
32
30
|
if (ids.length === 0)
|
|
33
31
|
return;
|
|
34
32
|
for (const id in bundle) {
|
|
@@ -22,12 +22,10 @@ const optimizeImports = () => {
|
|
|
22
22
|
return {
|
|
23
23
|
name: "carbon:optimize-imports",
|
|
24
24
|
script({ filename, content: raw }) {
|
|
25
|
-
// Skip files in node_modules to minimize unnecessary preprocessing
|
|
26
25
|
if (!filename)
|
|
27
26
|
return;
|
|
28
27
|
if (/node_modules/.test(filename))
|
|
29
28
|
return;
|
|
30
|
-
// Wrap the content in a `<script>` tag to parse it with the Svelte parser.
|
|
31
29
|
const content = `<script>${raw}</script>`;
|
|
32
30
|
const s = new magic_string_1.default(content);
|
|
33
31
|
(0, estree_walker_1.walk)((0, compiler_1.parse)(content), {
|
|
@@ -35,7 +33,7 @@ const optimizeImports = () => {
|
|
|
35
33
|
if (node.type === "ImportDeclaration") {
|
|
36
34
|
const import_name = node.source.value;
|
|
37
35
|
switch (import_name) {
|
|
38
|
-
case "carbon-components-svelte"
|
|
36
|
+
case "carbon-components-svelte":
|
|
39
37
|
rewriteImport(s, node, ({ imported, local }) => {
|
|
40
38
|
var _a;
|
|
41
39
|
const import_path = (_a = component_index_1.components[imported.name]) === null || _a === void 0 ? void 0 : _a.path;
|
|
@@ -44,8 +42,8 @@ const optimizeImports = () => {
|
|
|
44
42
|
: "";
|
|
45
43
|
});
|
|
46
44
|
break;
|
|
47
|
-
case "carbon-icons-svelte"
|
|
48
|
-
case "carbon-pictograms-svelte"
|
|
45
|
+
case "carbon-icons-svelte":
|
|
46
|
+
case "carbon-pictograms-svelte":
|
|
49
47
|
rewriteImport(s, node, ({ imported, local }) => {
|
|
50
48
|
return `import ${local.name} from "${import_name}/lib/${imported.name}.svelte";`;
|
|
51
49
|
});
|
package/dist/utils.js
CHANGED
|
@@ -11,5 +11,5 @@ function isCssFile(id) {
|
|
|
11
11
|
return constants_1.RE_EXT_CSS.test(id);
|
|
12
12
|
}
|
|
13
13
|
function isCarbonSvelteImport(id) {
|
|
14
|
-
return isSvelteFile(id) && id.includes("carbon-components-svelte"
|
|
14
|
+
return isSvelteFile(id) && id.includes("carbon-components-svelte");
|
|
15
15
|
}
|
package/package.json
CHANGED
|
@@ -1,33 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbon-preprocess-svelte",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.6",
|
|
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)",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"index:components": "bun scripts/index-components.ts",
|
|
11
|
-
"build": "bun --bun tsc -p tsconfig.build.json",
|
|
12
|
-
"test:e2e": "bun tests/test-e2e.ts",
|
|
13
|
-
"format": "bun --bun prettier --write . --cache"
|
|
14
|
-
},
|
|
15
9
|
"dependencies": {
|
|
16
10
|
"estree-walker": "^2.0.2",
|
|
17
|
-
"magic-string": "^0.30.
|
|
18
|
-
"postcss": "^8.4.
|
|
11
|
+
"magic-string": "^0.30.11",
|
|
12
|
+
"postcss": "^8.4.41",
|
|
19
13
|
"postcss-discard-empty": "^6.0.3"
|
|
20
14
|
},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"@types/bun": "latest",
|
|
23
|
-
"@types/jest": "latest",
|
|
24
|
-
"carbon-components-svelte": "0.85.0",
|
|
25
|
-
"prettier": "latest",
|
|
26
|
-
"svelte": "latest",
|
|
27
|
-
"typescript": "latest",
|
|
28
|
-
"vite": "latest",
|
|
29
|
-
"webpack": "latest"
|
|
30
|
-
},
|
|
31
15
|
"repository": {
|
|
32
16
|
"type": "git",
|
|
33
17
|
"url": "git+https://github.com/carbon-design-system/carbon-preprocess-svelte.git"
|
|
@@ -43,10 +27,6 @@
|
|
|
43
27
|
"optimize imports",
|
|
44
28
|
"optimize CSS"
|
|
45
29
|
],
|
|
46
|
-
"files": [
|
|
47
|
-
|
|
48
|
-
],
|
|
49
|
-
"maintainers": [
|
|
50
|
-
"Eric Liu (https://github.com/metonym)"
|
|
51
|
-
]
|
|
30
|
+
"files": ["dist"],
|
|
31
|
+
"maintainers": ["Eric Liu (https://github.com/metonym)"]
|
|
52
32
|
}
|