carbon-preprocess-svelte 0.10.0 → 0.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.
Files changed (48) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +162 -348
  3. package/dist/component-index.d.ts +4 -0
  4. package/dist/component-index.js +1924 -0
  5. package/dist/constants.d.ts +9 -14
  6. package/dist/constants.js +8 -0
  7. package/dist/index.d.ts +3 -4
  8. package/dist/index.js +12 -83167
  9. package/dist/plugins/OptimizeCssPlugin.d.ts +8 -0
  10. package/dist/plugins/OptimizeCssPlugin.js +49 -0
  11. package/dist/plugins/compare-diff.d.ts +6 -0
  12. package/dist/plugins/compare-diff.js +36 -0
  13. package/dist/plugins/create-optimized-css.d.ts +25 -0
  14. package/dist/plugins/create-optimized-css.js +90 -0
  15. package/dist/plugins/optimize-css.d.ts +3 -10
  16. package/dist/plugins/optimize-css.js +49 -0
  17. package/dist/preprocessors/optimize-imports.d.ts +3 -3
  18. package/dist/preprocessors/optimize-imports.js +65 -0
  19. package/dist/utils.d.ts +3 -11
  20. package/dist/utils.js +16 -0
  21. package/package.json +21 -49
  22. package/CHANGELOG.md +0 -136
  23. package/dist/build/build-components.d.ts +0 -9
  24. package/dist/build/build-elements.d.ts +0 -10
  25. package/dist/build/build-icons.d.ts +0 -15
  26. package/dist/build/build-pictograms.d.ts +0 -54
  27. package/dist/build/index.d.ts +0 -19
  28. package/dist/build/type.d.ts +0 -11
  29. package/dist/carbon-components-svelte.d.ts +0 -681
  30. package/dist/carbon-elements.d.ts +0 -833
  31. package/dist/carbon-icons.d.ts +0 -84420
  32. package/dist/carbon-pictograms.d.ts +0 -8839
  33. package/dist/extractors/extract-selectors.d.ts +0 -14
  34. package/dist/extractors/index.d.ts +0 -1
  35. package/dist/index.cjs.d.ts +0 -4
  36. package/dist/index.mjs +0 -83182
  37. package/dist/plugins/index.d.ts +0 -1
  38. package/dist/plugins/optimize-css.cjs.d.ts +0 -10
  39. package/dist/preprocessors/collect-headings.d.ts +0 -27
  40. package/dist/preprocessors/elements.d.ts +0 -22
  41. package/dist/preprocessors/icons.d.ts +0 -2
  42. package/dist/preprocessors/include.d.ts +0 -49
  43. package/dist/preprocessors/index.d.ts +0 -6
  44. package/dist/preprocessors/pictograms.d.ts +0 -2
  45. package/dist/presets/index.d.ts +0 -1
  46. package/dist/presets/preset-carbon.d.ts +0 -7
  47. package/dist/walk-and-replace.d.ts +0 -117
  48. package/src/carbon-components-svelte.js +0 -513
package/LICENSE CHANGED
@@ -198,4 +198,4 @@
198
198
  distributed under the License is distributed on an "AS IS" BASIS,
199
199
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
200
  See the License for the specific language governing permissions and
201
- limitations under the License.
201
+ limitations under the License.
package/README.md CHANGED
@@ -4,42 +4,31 @@
4
4
  ![GitHub](https://img.shields.io/github/license/ibm/carbon-preprocess-svelte?color=262626&style=for-the-badge)
5
5
  ![npm downloads to date](https://img.shields.io/npm/dt/carbon-preprocess-svelte?color=262626&style=for-the-badge)
6
6
 
7
- > Collection of [Svelte preprocessors](https://svelte.dev/docs#svelte_preprocess) for the Carbon Design System
7
+ > [Svelte preprocessors](https://svelte.dev/docs/svelte-compiler#types-preprocessor) for the Carbon Design System
8
8
 
9
9
  ## Installation
10
10
 
11
- **Yarn**
11
+ Install `carbon-preprocess-svelte` as a development dependency.
12
12
 
13
13
  ```sh
14
+ # Yarn
14
15
  yarn add -D carbon-preprocess-svelte
15
- ```
16
-
17
- **NPM**
18
16
 
19
- ```sh
17
+ # npm
20
18
  npm i -D carbon-preprocess-svelte
21
- ```
22
-
23
- **pnpm**
24
19
 
25
- ```sh
20
+ # pnpm
26
21
  pnpm i -D carbon-preprocess-svelte
27
22
  ```
28
23
 
29
24
  ## Usage
30
25
 
31
- This library contains the following preprocessors and plugins:
32
-
33
- - **optimizeImports**: rewrites Carbon Svelte imports to their source path in the `script` block
34
- - **optimizeCss**: Rollup plugin that removes unused CSS using [PurgeCSS](https://github.com/FullHuman/purgecss)
35
- - **elements**: computes [Carbon tokens](https://www.carbondesignsystem.com/guidelines/themes/overview#tokens) in the `style` block
36
- - **icons**: inlines [Carbon icons](https://www.carbondesignsystem.com/guidelines/icons/library/) in the `markup` block
37
- - **pictograms**: inlines [Carbon pictograms](https://www.carbondesignsystem.com/guidelines/pictograms/library/) in the `markup` block
38
- - **collectHeadings**: extracts heading elements (e.g., `<h1>`, `<h2>`) from the `markup`
26
+ - [**optimizeImports**](#optimizeimports): Svelte preprocessor that rewrites Carbon Svelte imports to their source path in the `script` block, making development compile times dramatically faster.
27
+ - [**optimizeCss**](#optimizecss): Vite/Rollup plugin that removes unused Carbon styles, resulting in smaller CSS bundles.
39
28
 
40
29
  ### `optimizeImports`
41
30
 
42
- `optimizeImports` is a Svelte script preprocessor that rewrites base imports from Carbon components/icons/pictograms packages to their source Svelte code paths. This can greatly speed up compile times during development while preserving typeahead and autocompletion hinting offered by integrated development environments (IDE) like VSCode.
31
+ `optimizeImports` is a Svelte preprocessor that rewrites barrel imports from Carbon components/icons/pictograms packages to their source Svelte code paths. This can significantly speed up development and production build compile times while preserving typeahead and autocompletion offered by integrated development environments (IDE) like VS Code.
43
32
 
44
33
  The preprocessor optimizes imports from the following packages:
45
34
 
@@ -47,420 +36,245 @@ The preprocessor optimizes imports from the following packages:
47
36
  - [carbon-icons-svelte](https://github.com/carbon-design-system/carbon-icons-svelte)
48
37
  - [carbon-pictograms-svelte](https://github.com/carbon-design-system/carbon-pictograms-svelte)
49
38
 
50
- **Example**
51
-
52
39
  ```diff
53
40
  - import { Button } from "carbon-components-svelte";
54
- - import { Add16 } from "carbon-icons-svelte";
55
- - import { Airplane } from "carbon-pictograms-svelte";
56
- + import Button from "carbon-components-svelte/Button.svelte";
57
- + import Add16 from "carbon-icons-svelte/lib/Add16.svelte";
58
- + import Airplane from "carbon-pictograms-svelte/lib/Airplane.svelte";
59
- ```
60
-
61
- **Note**
62
-
63
- A minimum version of `carbon-preprocess-svelte@0.9.0` is required for `carbon-component-svelte@0.63.0`.
64
-
65
- A minimum version of `carbon-preprocess-svelte@0.8.0` is required for `carbon-icons-svelte@11`.
41
+ + import Button from "carbon-components-svelte/src/Button/Button.svelte";
66
42
 
67
- #### Usage
68
-
69
- ```js
70
- // svelte.config.js
71
- import { optimizeImports } from "carbon-preprocess-svelte";
43
+ - import { Add } from "carbon-icons-svelte";
44
+ + import Add from "carbon-icons-svelte/lib/Add.svelte";
72
45
 
73
- export default {
74
- preprocess: [optimizeImports()],
75
- };
46
+ - import { Airplane } from "carbon-pictograms-svelte";
47
+ + import Airplane from "carbon-pictograms-svelte/lib/Airplane.svelte";
76
48
  ```
77
49
 
78
- ### `optimizeCss`
50
+ > [!NOTE]
51
+ > When this preprocessor was first created, there was no workaround to optimize slow cold start times with Vite in development.
52
+ > As of today, [@sveltejs/vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte) enables [`prebundleSvelteLibraries`](https://github.com/sveltejs/vite-plugin-svelte/blob/ba4ac32cf5c3e9c048d1ac430c1091ca08eaa130/docs/config.md#prebundlesveltelibraries), which pre-bundles Svelte libraries to improve cold start times for Vite-based set-ups.
53
+ > However, this preprocessor is still useful for non-Vite bundlers, like Rollup and Webpack.
79
54
 
80
- `optimizeCss` is a Rollup plugin that removes unused Carbon CSS. It extracts selectors based on a Svelte component's markup and style content and uses [PurgeCSS](https://github.com/FullHuman/purgecss) to prune any unused styles.
55
+ #### SvelteKit
81
56
 
82
- #### Usage
83
-
84
- `optimizeCss` should be added to the list of `vite.plugins`. Take care to only run the plugin when building for production.
57
+ See [examples/sveltekit](examples/sveltekit).
85
58
 
86
59
  ```js
87
60
  // svelte.config.js
88
61
  import adapter from "@sveltejs/adapter-static";
89
- import { optimizeCss } from "carbon-preprocess-svelte";
62
+ import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
63
+ import { optimizeImports } from "carbon-preprocess-svelte";
90
64
 
91
- export default {
65
+ /** @type {import('@sveltejs/kit').Config} */
66
+ const config = {
67
+ preprocess: [
68
+ // Preprocessors are run in sequence.
69
+ // If using TypeScript, the code must be transpiled first.
70
+ vitePreprocess(),
71
+ optimizeImports(),
72
+ ],
92
73
  kit: {
93
74
  adapter: adapter(),
94
- vite: {
95
- plugins: [process.env.NODE_ENV === "production" && optimizeCss()],
96
- },
97
75
  },
98
76
  };
99
- ```
100
77
 
101
- #### API
102
-
103
- ```ts
104
- interface OptimizeCssOptions {
105
- safelist: {
106
- standard?: Array<RegExp | string>;
107
- deep?: RegExp[];
108
- greedy?: RegExp[];
109
- };
110
- }
78
+ export default config;
111
79
  ```
112
80
 
113
- ### `elements`
114
-
115
- `elements` is a Svelte style preprocessor that rewrites [Carbon Design System tokens](https://www.carbondesignsystem.com/guidelines/themes/overview#tokens) to their computed values. The purpose is to use design system token names (e.g., `"interactive-01"`) instead of hardcoded values (e.g., `"#0f62fe"`).
116
-
117
- **Before**
81
+ #### Vite
118
82
 
119
- ```svelte
120
- <style>
121
- h1,
122
- h2 {
123
- font-weight: "semibold";
124
- background: "ui-01";
125
- }
83
+ See [examples/vite](examples/vite).
126
84
 
127
- div {
128
- font: "expressive-heading-01";
129
- transition: background "easing.standard.productive";
130
- }
85
+ ```js
86
+ // vite.config.js
87
+ import { svelte } from "@sveltejs/vite-plugin-svelte";
88
+ import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
89
+ import { optimizeImports } from "carbon-preprocess-svelte";
131
90
 
132
- @media (between: 321px) and (md) {
133
- div {
134
- color: "blue-60";
135
- }
136
- }
137
- </style>
91
+ /** @type {import('vite').UserConfig} */
92
+ export default {
93
+ plugins: [
94
+ svelte({
95
+ preprocess: [
96
+ // Preprocessors are run in sequence.
97
+ // If using TypeScript, the code must be transpiled first.
98
+ vitePreprocess(),
99
+ optimizeImports(),
100
+ ],
101
+ }),
102
+ ],
103
+ };
138
104
  ```
139
105
 
140
- **After**
141
-
142
- ```svelte
143
- <style>
144
- h1,
145
- h2 {
146
- font-weight: 600;
147
- background: #f4f4f4;
148
- }
149
-
150
- div {
151
- font-size: 0.875rem;
152
- font-weight: 600;
153
- line-height: 1.25;
154
- letter-spacing: 0.16px;
155
- transition: background cubic-bezier(0.2, 0, 0.38, 0.9);
156
- }
157
-
158
- @media (between: 321px) and (md) {
159
- div {
160
- color: #0f62fe;
161
- }
162
- }
163
- </style>
164
- ```
106
+ #### Rollup
165
107
 
166
- #### Usage
108
+ This code is abridged; see [examples/rollup](examples/rollup) for a full set-up.
167
109
 
168
110
  ```js
169
- // svelte.config.js
170
- import { elements } from "carbon-preprocess-svelte";
111
+ // rollup.config.js
112
+ import svelte from "rollup-plugin-svelte";
113
+ import { optimizeImports } from "carbon-preprocess-svelte";
171
114
 
172
115
  export default {
173
- preprocess: [elements()],
116
+ plugins: [
117
+ svelte({
118
+ preprocess: [optimizeImports()],
119
+ }),
120
+ ],
174
121
  };
175
122
  ```
176
123
 
177
- #### API
124
+ #### Webpack
178
125
 
179
- ```ts
180
- interface ElementsOptions {
181
- /**
182
- * Specify the Carbon theme
183
- * Setting to "all" will also enable `cssVars`
184
- * @default "white"
185
- */
186
- theme: "white" | "g10" | "g90" | "g100" | "all";
126
+ This code is abridged; see [examples/webpack](examples/webpack) for a full set-up.
187
127
 
188
- /**
189
- * Set to `true` for tokens to be re-written as CSS variables
190
- * Automatically set to `true` if theme is "all"
191
- * @example
192
- * "spacing-05" --> var(--cds-spacing-05)
193
- * "ui-01" --> var(--cds-ui-01)
194
- * @default false
195
- */
196
- cssVars: boolean;
197
- }
128
+ ```js
129
+ // webpack.config.js
130
+ const { optimizeImports } = require("carbon-preprocess-svelte");
131
+
132
+ module.exports = {
133
+ module: {
134
+ rules: [
135
+ {
136
+ test: /\.svelte$/,
137
+ use: {
138
+ loader: "svelte-loader",
139
+ options: {
140
+ hotReload: !PROD,
141
+ preprocess: [optimizeImports()],
142
+ compilerOptions: { dev: !PROD },
143
+ },
144
+ },
145
+ },
146
+ ],
147
+ },
148
+ };
198
149
  ```
199
150
 
200
- ### `icons`
201
-
202
- `icons` is a Svelte markup preprocessor that inlines [Carbon SVG icons](https://www.carbondesignsystem.com/guidelines/icons/library/).
151
+ ### `optimizeCss`
203
152
 
204
- The only required attribute is `name`, which represents the module name of the icon. Refer to [carbon-icons-svelte/ICON_INDEX.md](https://github.com/carbon-design-system/carbon-icons-svelte/blob/master/ICON_INDEX.md) for a list of supported icons.
153
+ `optimizeCss` is a Vite plugin that removes unused Carbon styles at build time. The plugin is compatible with Rollup ([Vite](https://vitejs.dev/guide/api-plugin) extends the Rollup plugin API).
205
154
 
206
- **Example**
155
+ `carbon-components-svelte@0.85.0` or greater is required.
207
156
 
208
157
  ```diff
209
- - <icon name="Add16" />
210
- + <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="currentColor" focusable="false" preserveAspectRatio="xMidYMid meet" width=16 height=16><path d="M17 15L17 8 15 8 15 15 8 15 8 17 15 17 15 24 17 24 17 17 24 17 24 15z"></path></svg>
211
- ```
158
+ $ vite build
212
159
 
213
- #### Usage
160
+ Optimized index-CU4gbKFa.css
161
+ - Before: 606.26 kB
162
+ + After: 53.22 kB (-91.22%)
214
163
 
215
- ```js
216
- // svelte.config.js
217
- import { icons } from "carbon-preprocess-svelte";
218
-
219
- export default {
220
- preprocess: [icons()],
221
- };
164
+ dist/index.html 0.34 kB │ gzip: 0.24 kB
165
+ dist/assets/index-CU4gbKFa.css 53.22 kB │ gzip: 6.91 kB
166
+ dist/assets/index-Ceijs3eO.js 53.65 kB gzip: 15.88 kB
222
167
  ```
223
168
 
224
- ### `pictograms`
225
-
226
- `pictograms` is a Svelte markup preprocessor that inlines [Carbon SVG pictograms](https://www.carbondesignsystem.com/guidelines/pictograms/library/).
169
+ > [!NOTE]
170
+ > This is a plugin and not a Svelte preprocessor. It should be added to the list of `vite.plugins`. For Vite set-ups, this plugin is only run when building the app. For Rollup and Webpack, you should conditionally apply the plugin to only execute when building for production.
227
171
 
228
- The only required attribute is `name`, which represents the module name of the pictogram. Refer to [carbon-pictograms-svelte/PICTOGRAM_INDEX.md](https://github.com/carbon-design-system/carbon-pictograms-svelte/blob/master/PICTOGRAM_INDEX.md) for a list of supported pictograms.
172
+ #### SvelteKit
229
173
 
230
- **Example**
174
+ See [examples/sveltekit](examples/sveltekit).
231
175
 
232
- ```diff
233
- - <pictogram name="Airplane" />
234
- + <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="currentColor" focusable="false" preserveAspectRatio="xMidYMid meet" width=64 height=64><path d="M22,31.36c-0.038,0-0.076-0.007-0.114-0.019L16,29.38l-5.886,1.962c-0.11,0.035-0.231,0.018-0.324-0.05 C9.696,31.225,9.64,31.115,9.64,31v-2c0-0.104,0.044-0.202,0.123-0.271l3.877-3.393V5.169c0-1.419,0.594-4.529,2.36-4.529 s2.36,3.11,2.36,4.529v5.166l2.279,1.759V10h0.721v2.65l2.279,1.759V12h0.721v2.965l4.859,3.75c0.089,0.068,0.141,0.174,0.141,0.285 v4.5c0,0.128-0.068,0.246-0.179,0.311c-0.112,0.066-0.247,0.065-0.359,0.003l-10.458-5.916l-0.004,7.439l3.877,3.393 c0.078,0.068,0.123,0.167,0.123,0.271v2c0,0.115-0.056,0.225-0.149,0.292C22.148,31.337,22.074,31.36,22,31.36z M16,28.64 c0.039,0,0.077,0.007,0.114,0.019l5.526,1.843v-1.338l-3.877-3.393c-0.078-0.068-0.123-0.167-0.123-0.271l0.005-8.22 c0-0.128,0.068-0.246,0.179-0.311c0.112-0.064,0.247-0.065,0.359-0.002l10.457,5.916v-3.706l-10.859-8.38 c-0.089-0.068-0.141-0.174-0.141-0.285V5.169c0-1.33-0.562-3.81-1.64-3.81c-1.077,0-1.64,2.48-1.64,3.81V25.5 c0,0.104-0.044,0.202-0.123,0.271l-3.877,3.393v1.338l5.526-1.843C15.923,28.646,15.961,28.64,16,28.64z M3,23.86 c-0.062,0-0.125-0.017-0.18-0.049c-0.111-0.064-0.18-0.183-0.18-0.312V19c0-0.112,0.052-0.218,0.141-0.286l4.859-3.721V12h0.72 v2.441l2.28-1.746V10h0.72v2.873c0,0.112-0.052,0.218-0.141,0.286L3.36,19.178v3.699l8.46-4.884l0.36,0.623l-9,5.195 C3.125,23.844,3.062,23.86,3,23.86z"></path></svg>
176
+ ```js
177
+ // vite.config.js
178
+ import { sveltekit } from "@sveltejs/kit/vite";
179
+ import { optimizeCss } from "carbon-preprocess-svelte";
180
+ import { defineConfig } from "vite";
235
181
 
182
+ export default defineConfig({
183
+ plugins: [sveltekit(), optimizeCss()],
184
+ });
236
185
  ```
237
186
 
238
- #### Usage
187
+ #### Vite
188
+
189
+ See [examples/vite](examples/vite).
239
190
 
240
191
  ```js
241
- // svelte.config.js
242
- import { pictograms } from "carbon-preprocess-svelte";
192
+ // vite.config.js
193
+ import { svelte } from "@sveltejs/vite-plugin-svelte";
194
+ import { optimizeCss } from "carbon-preprocess-svelte";
243
195
 
196
+ /** @type {import('vite').UserConfig} */
244
197
  export default {
245
- preprocess: [pictograms()],
198
+ plugins: [svelte(), optimizeCss()],
246
199
  };
247
200
  ```
248
201
 
249
- ### `collectHeadings`
250
-
251
- `collectHeadings` extracts heading elements from markup with an optional callback to modify the source content. This can be used to create a table of contents.
252
-
253
- **Example**
254
-
255
- Markup:
256
-
257
- ```svelte
258
- <main>
259
- <!-- toc -->
260
- <h1 id="h1">Heading 1</h1>
261
- <h2 id="h2"><strong>Heading</strong> 2</h2>
262
- <h3>Heading 3</h3>
263
- </main>
264
- ```
202
+ #### Rollup
265
203
 
266
- Extracted headings:
204
+ This code is abridged; see [examples/rollup](examples/rollup) for a full set-up.
267
205
 
268
206
  ```js
269
- const headings = [
270
- { id: "h1", text: "Heading 1", level: 1 },
271
- { id: "h2-0", text: "Heading 2", level: 2 },
272
- { id: "h2-1", text: "Heading 2", level: 2 },
273
- { id: undefined, text: "Heading 3", level: 3 },
274
- ];
275
- ```
276
-
277
- #### Usage
207
+ // rollup.config.js
208
+ import svelte from "rollup-plugin-svelte";
209
+ import { optimizeCss } from "carbon-preprocess-svelte";
278
210
 
279
- In the following example, we create a table of contents from the `<h2>` elements in a Svelte file. In the `afterCollect` callback, we replace `<!-- toc -->` with the table of contents.
280
-
281
- ```js
282
- // svelte.config.js
283
- import { collectHeadings } from "carbon-preprocess-svelte";
211
+ const production = !process.env.ROLLUP_WATCH;
284
212
 
285
213
  export default {
286
- preprocess: [
287
- collectHeadings({
288
- afterCollect: (headings, content) => {
289
- const toc = headings
290
- .filter((heading) => heading.level === 2)
291
- .map((item) => `<li><a href="#${item.id}">${item.text}</a></li>`)
292
- .join("");
293
-
294
- return content.replace("<!-- toc -->", `<ul>${toc}</ul>`);
295
- },
214
+ plugins: [
215
+ svelte({
216
+ preprocess: [optimizeImports()],
296
217
  }),
218
+
219
+ // Only apply the plugin when building for production.
220
+ production && optimizeCss(),
297
221
  ],
298
222
  };
299
223
  ```
300
224
 
301
- #### API
302
-
303
- ```js
304
- interface CollectHeadingsOptions {
305
- /**
306
- * Specify the filename pattern to process
307
- * Defaults to files ending with ".svelte"
308
- * @default /\.(svelte)$/
309
- */
310
- test: RegExp;
311
-
312
- /**
313
- * Optional callback to transform the content after extracting all headings
314
- */
315
- afterCollect: (
316
- headings: Array<{
317
- id?: string,
318
- text: string,
319
- level: 1 | 2 | 3 | 4 | 5 | 6,
320
- }>,
321
- content: string
322
- ) => string;
323
- }
324
- ```
325
-
326
- ### `include`
327
-
328
- `include` prepends or appends arbitrary content to the script and markup blocks.
329
-
330
- **Example**
331
-
332
- ```diff
333
- <script>
334
- + import { CodeSnippet } from "carbon-components-svelte";
335
- import { onMount } from "svelte";
336
- </script>
337
-
338
- + <!-- toc -->
339
-
340
- <h1>Title</h1>
341
-
342
- + <p>Summary</p>
343
- ```
225
+ #### Webpack
344
226
 
345
- #### Usage
227
+ Webpack users should use the `OptimizeCssPlugin`. The plugin API is identical to the Vite plugin.
346
228
 
347
- In the above example, we prepend script content that imports the `CodeSnippet` component from `carbon-components-svelte`. In the markup, we prepend `<!-- toc -->` and append `<p>Summary</p>`.
229
+ This code is abridged; see [examples/webpack](examples/webpack) for a full set-up.
348
230
 
349
231
  ```js
350
- // svelte.config.js
351
- import { include } from "carbon-preprocess-svelte";
232
+ // webpack.config.js
233
+ const { OptimizeCssPlugin } = require("carbon-preprocess-svelte");
352
234
 
353
- export default {
354
- preprocess: [
355
- include({
356
- script: [
357
- {
358
- content: 'import { CodeSnippet } from "carbon-components-svelte";',
359
- },
360
- ],
361
- markup: [
362
- { content: "<!-- toc -->" },
363
- {
364
- content: "<p>Summary</p>",
365
- behavior: "append",
366
- },
367
- ],
368
- }),
235
+ const PROD = process.env.NODE_ENV === "production";
236
+
237
+ module.exports = {
238
+ plugins: [
239
+ // Only apply the plugin when building for production.
240
+ PROD && new OptimizeCssPlugin(),
369
241
  ],
370
242
  };
371
243
  ```
372
244
 
373
- #### API
245
+ #### `optimizeCss` API
374
246
 
375
- By default, the `include` preprocessor will _prepend_ content to the content block. Set `behavior` to `"append"` to append the content.
376
-
377
- ```js
378
- interface PreprocessIncludeOptions {
247
+ ```ts
248
+ optimizeCss({
379
249
  /**
380
- * Specify the filename pattern to process
381
- * Defaults to files ending with ".svelte"
382
- * @default /\.(svelte)$/
250
+ * By default, the plugin will print the size
251
+ * difference between the original and optimized CSS.
252
+ *
253
+ * Set to `false` to disable verbose logging.
254
+ * @default true
383
255
  */
384
- test?: RegExp;
385
-
386
- script: Array<{
387
- /**
388
- * Specify the content the prepend or append
389
- * @example
390
- * import { CodeSnippet } from "carbon-components-svelte";
391
- */
392
- content: string,
393
-
394
- /**
395
- * Specify the filename pattern to process
396
- * Defaults to files ending with ".svelte"
397
- * @default /\.(svelte)$/
398
- */
399
- test?: RegExp,
400
-
401
- /**
402
- * Specify whether the content should be prepended or appended
403
- * @default "prepend"
404
- */
405
- behavior?: "prepend" | "append",
406
- }>;
407
-
408
- markup: Array<{
409
- /**
410
- * Specify the content the prepend or append
411
- * @example
412
- * <ul>Table of Contents</ul>
413
- */
414
- content: string,
415
-
416
- /**
417
- * Specify the filename pattern to process
418
- * Defaults to files ending with ".svelte"
419
- * @default /\.(svelte)$/
420
- */
421
- test?: RegExp,
422
-
423
- /**
424
- * Specify whether the content should be prepended or appended
425
- * @default "prepend"
426
- */
427
- behavior?: "prepend" | "append",
428
- }>;
429
- }
430
- ```
431
-
432
- ## Presets
433
-
434
- ```js
435
- // svelte.config.js
436
- import { presetCarbon } from "carbon-preprocess-svelte";
256
+ verbose: false,
437
257
 
438
- export default {
439
- preprocess: presetCarbon(),
440
-
441
- // if using other preprocessors
442
- // preprocess: [...presetCarbon()],
443
- };
258
+ /**
259
+ * By default, pre-compiled Carbon StyleSheets ship `@font-face` rules
260
+ * for all available IBM Plex fonts, many of which are not actually
261
+ * used in Carbon Svelte components.
262
+ *
263
+ * The default behavior is to preserve the following IBM Plex fonts:
264
+ * - IBM Plex Sans (300/400/600-weight and normal-font-style rules)
265
+ * - IBM Plex Mono (400-weight and normal-font-style rules)
266
+ *
267
+ * Set to `true` to disable this behavior and
268
+ * retain *all* IBM Plex `@font-face` rules.
269
+ * @default false
270
+ */
271
+ preserveAllIBMFonts: false,
272
+ });
444
273
  ```
445
274
 
446
- ## Sample SvelteKit set-up
275
+ ## Examples
447
276
 
448
- ```js
449
- // svelte.config.js
450
- import adapter from "@sveltejs/adapter-static";
451
- import { optimizeImports, optimizeCss } from "carbon-preprocess-svelte";
452
-
453
- /** @type {import('@sveltejs/kit').Config} */
454
- export default {
455
- preprocess: [optimizeImports()],
456
- kit: {
457
- adapter: adapter(),
458
- vite: {
459
- plugins: [process.env.NODE_ENV === "production" && optimizeCss()],
460
- },
461
- },
462
- };
463
- ```
277
+ Refer to [examples](examples) for common set-ups.
464
278
 
465
279
  ## Contributing
466
280
 
@@ -0,0 +1,4 @@
1
+ export declare const components: Record<string, {
2
+ path: string;
3
+ classes: string[];
4
+ }>;