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/README.md
CHANGED
|
@@ -4,31 +4,35 @@
|
|
|
4
4
|

|
|
5
5
|

|
|
6
6
|
|
|
7
|
-
> [Svelte preprocessors](https://svelte.dev/docs/svelte-compiler#types-preprocessor) 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
11
|
Install `carbon-preprocess-svelte` as a development dependency.
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
# Yarn
|
|
15
|
-
yarn add -D carbon-preprocess-svelte
|
|
16
|
-
|
|
17
14
|
# npm
|
|
18
15
|
npm i -D carbon-preprocess-svelte
|
|
19
16
|
|
|
20
17
|
# pnpm
|
|
21
18
|
pnpm i -D carbon-preprocess-svelte
|
|
19
|
+
|
|
20
|
+
# Yarn
|
|
21
|
+
yarn add -D carbon-preprocess-svelte
|
|
22
|
+
|
|
23
|
+
# Bun
|
|
24
|
+
bun add -D carbon-preprocess-svelte
|
|
22
25
|
```
|
|
23
26
|
|
|
24
27
|
## Usage
|
|
25
28
|
|
|
26
29
|
- [**optimizeImports**](#optimizeimports): Svelte preprocessor that rewrites Carbon Svelte imports to their source path in the `script` block, making development compile times dramatically faster.
|
|
27
30
|
- [**optimizeCss**](#optimizecss): Vite/Rollup plugin that removes unused Carbon styles, resulting in smaller CSS bundles.
|
|
31
|
+
- [**OptimizeCssPlugin**](#optimizecssplugin): The corresponding `optimizeCss` plugin for Webpack that removes unused Carbon styles.
|
|
28
32
|
|
|
29
33
|
### `optimizeImports`
|
|
30
34
|
|
|
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
|
|
35
|
+
`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 build compile times while preserving typeahead and autocompletion offered by integrated development environments (IDE) like VS Code.
|
|
32
36
|
|
|
33
37
|
The preprocessor optimizes imports from the following packages:
|
|
34
38
|
|
|
@@ -49,8 +53,8 @@ The preprocessor optimizes imports from the following packages:
|
|
|
49
53
|
|
|
50
54
|
> [!NOTE]
|
|
51
55
|
> 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) by default, which greatly improves development times.
|
|
53
|
-
> However, this preprocessor is still useful for non-Vite bundlers, like Rollup and Webpack.
|
|
56
|
+
> As of today, [@sveltejs/vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte) enables [`prebundleSvelteLibraries: true`](https://github.com/sveltejs/vite-plugin-svelte/blob/ba4ac32cf5c3e9c048d1ac430c1091ca08eaa130/docs/config.md#prebundlesveltelibraries) by default, which greatly improves development times.
|
|
57
|
+
> However, this preprocessor is still useful for non-Vite bundlers, like Rollup and Webpack. Additionally, this preprocessor can still improve cold start development times, even when `prebundleSvelteLibraries` is enabled.
|
|
54
58
|
|
|
55
59
|
#### SvelteKit
|
|
56
60
|
|
|
@@ -152,8 +156,6 @@ module.exports = {
|
|
|
152
156
|
|
|
153
157
|
`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).
|
|
154
158
|
|
|
155
|
-
`carbon-components-svelte@0.85.0` or greater is required.
|
|
156
|
-
|
|
157
159
|
```diff
|
|
158
160
|
$ vite build
|
|
159
161
|
|
|
@@ -167,7 +169,7 @@ dist/assets/index-Ceijs3eO.js 53.65 kB │ gzip: 15.88 kB
|
|
|
167
169
|
```
|
|
168
170
|
|
|
169
171
|
> [!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
|
|
172
|
+
> 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 not run_ during development and is only executed when building the app (i.e., `vite build`). For Rollup and Webpack, you should conditionally apply the plugin to only execute when building for production.
|
|
171
173
|
|
|
172
174
|
#### SvelteKit
|
|
173
175
|
|
|
@@ -222,26 +224,6 @@ export default {
|
|
|
222
224
|
};
|
|
223
225
|
```
|
|
224
226
|
|
|
225
|
-
#### Webpack
|
|
226
|
-
|
|
227
|
-
Webpack users should use the `OptimizeCssPlugin`. The plugin API is identical to the Vite plugin.
|
|
228
|
-
|
|
229
|
-
This code is abridged; see [examples/webpack](examples/webpack) for a full set-up.
|
|
230
|
-
|
|
231
|
-
```js
|
|
232
|
-
// webpack.config.js
|
|
233
|
-
const { OptimizeCssPlugin } = require("carbon-preprocess-svelte");
|
|
234
|
-
|
|
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(),
|
|
241
|
-
],
|
|
242
|
-
};
|
|
243
|
-
```
|
|
244
|
-
|
|
245
227
|
#### `optimizeCss` API
|
|
246
228
|
|
|
247
229
|
```ts
|
|
@@ -272,6 +254,26 @@ optimizeCss({
|
|
|
272
254
|
});
|
|
273
255
|
```
|
|
274
256
|
|
|
257
|
+
### `OptimizeCssPlugin`
|
|
258
|
+
|
|
259
|
+
For Webpack users, `OptimizeCssPlugin` is a drop-in replacement for `optimizeCss`. The plugin API is identical to that of `optimizeCss`.
|
|
260
|
+
|
|
261
|
+
This code is abridged; see [examples/webpack](examples/webpack) for a full set-up.
|
|
262
|
+
|
|
263
|
+
```js
|
|
264
|
+
// webpack.config.js
|
|
265
|
+
const { OptimizeCssPlugin } = require("carbon-preprocess-svelte");
|
|
266
|
+
|
|
267
|
+
const PROD = process.env.NODE_ENV === "production";
|
|
268
|
+
|
|
269
|
+
module.exports = {
|
|
270
|
+
plugins: [
|
|
271
|
+
// Only apply the plugin when building for production.
|
|
272
|
+
PROD && new OptimizeCssPlugin(),
|
|
273
|
+
],
|
|
274
|
+
};
|
|
275
|
+
```
|
|
276
|
+
|
|
275
277
|
## Examples
|
|
276
278
|
|
|
277
279
|
Refer to [examples](examples) for common set-ups.
|