Comments (6)
For me, I ran into the same issues. It took very long without the pre-processor.
In @sveltejs/kit: 1.0.0-next.508
and with the adapter-node instead of adapter-auto in svelte.config.js so far all carbon-components-svelte seem to be working.
Here is my svelte.config.js
import adapter from '@sveltejs/adapter-node';
import preprocess from 'svelte-preprocess';
import { optimizeImports } from "carbon-preprocess-svelte";
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [preprocess(),optimizeImports()],
kit: { adapter: adapter(), }
};
export default config;
from carbon-preprocess-svelte.
Tested today with updated dependencies and the Cloudflare adapter. Now, it works!
Build is a bit smaller 1.8M to 1.5M. Nice.
I was expecting a smaller build because my app is very simple but the CSS file still large (same size as before):
596K _layout-981051fa.css
It tried to replace all import {Grid } from 'carbon-components-svelte'
by import Grid from 'carbon-components-svelte/src/Grid/Grid.svelte';
as described in https://github.com/carbon-design-system/carbon-preprocess-svelte#optimizeimports but it produces the same build output.
from carbon-preprocess-svelte.
@stephane optimizeImports
rewrites component imports to speed up development and build compile times. There shouldn't be a difference in bundle output since unused imports should be tree-shaken when building for production.
optimizeCss might be what you're looking for if you want to decrease the final CSS size
from carbon-preprocess-svelte.
I'm happy to report that the config I originally posted seems to be working now, not sure if just some version changes fixed it or what exactly happened. Unfortunately, there still seem to be some issues with performance optimization. Using SvelteKit, and the svelte.config.js file posted above, loading a page with a datatable doesn't even start for ~1.5 minutes, and takes up to 6 minutes to finish:
Using vite in debug mode, I can see a whole bunch of icons and assets that aren't currently in use are being processed.
vite.config.js:
import { sveltekit } from '@sveltejs/kit/vite';
import { optimizeCss } from 'carbon-preprocess-svelte';
/** @type {import('vite').UserConfig} */
const config = {
plugins: [sveltekit(), process.env.NODE_ENV === "production" && optimizeCss()],
build: {
target: [ 'es2020' ]
}
};
export default config;
svelte.config.js:
import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';
import { optimizeImports } from 'carbon-preprocess-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: [preprocess(), optimizeImports()],
kit: {
adapter: adapter()
}
};
export default config;
Versions:
- carbon-components-svelte: 0.67.9
- carbon-preprocess-svelte: 0.9.1
- svelte-kit: 1.0.0-next.510
- vite: 3.1.4
from carbon-preprocess-svelte.
@metonym, I didn't mention I used optimizeCss
and to be sure optimizeCss
was enabled I removed the test against NODE_ENV
.
My conf was:
import adapter from '@sveltejs/adapter-cloudflare';
import preprocess from 'svelte-preprocess';
import { optimizeImports, optimizeCss } from 'carbon-preprocess-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: [preprocess(), optimizeImports()],
kit: {
adapter: adapter()
},
vite: {
plugins: [process.env.NODE_ENV === 'production' && optimizeCss()]
}
};
export default config;
from carbon-preprocess-svelte.
Regarding the follow up concern I shared above regarding long load times, I'm happy to report that I was able to overcome that as well.
I was importing icons in a .ts
file, which I'm guessing avoids pre-processing. By converting that TS file to a .svelte
file with a <script context="module" lang="ts">
, optimization is working again and my dev load times are reasonable.
from carbon-preprocess-svelte.
Related Issues (20)
- ParseError with scss inside component HOT 2
- optimizeCss removes carbon-charts css HOT 2
- Unexpected Token Error when importing types HOT 8
- `optimizeImports` incompatible with Carbon icons v11 HOT 4
- Optimize Css problem HOT 2
- Notification breaks optimizeCss() HOT 1
- `elements` cannot process CSS variables
- Run optimizeImports for all imports on dev server start HOT 4
- Using optimizeCss with tailwind breaking css in sveltekit. HOT 1
- Docs and e2e examples are out of date HOT 1
- Got Error: Unexpected option config.kit.vite when execute yarn dev HOT 3
- Svelte 4 compatibility for peer dependencies HOT 3
- Request fix optimizeImport module support carbon-icon-component v12 HOT 1
- This library needs a rewrite HOT 1
- Update docs on usage HOT 1
- Minor dependency update breaks this package HOT 4
- optimizeCss v0.11.0 breaks image styling on production builds with Sveltekit HOT 3
- `optimizeCss` should not print diff if there was no diff
- Compatibility issues with Svelte 5 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from carbon-preprocess-svelte.