Code Monkey home page Code Monkey logo

Comments (6)

Strunck avatar Strunck commented on June 3, 2024

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.

stephane avatar stephane commented on June 3, 2024

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.

metonym avatar metonym commented on June 3, 2024

@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.

willbicks avatar willbicks commented on June 3, 2024

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:

image

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.

stephane avatar stephane commented on June 3, 2024

@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.

willbicks avatar willbicks commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.