Bundle size using sprinkles #421
-
I've tried to bundle an example from https://vanilla-extract.style/documentation/sprinkles-api/ // src/sprinkles.css.ts
import {
defineProperties,
createSprinkles
} from '@vanilla-extract/sprinkles';
const space = {
none: 0,
small: '4px',
medium: '8px',
large: '16px'
};
const colors = {
blue50: '#eff6ff',
blue100: '#dbeafe',
blue200: '#bfdbfe'
// etc.
};
const responsiveProperties = defineProperties({
conditions: {
mobile: {},
tablet: { '@media': 'screen and (min-width: 768px)' },
desktop: { '@media': 'screen and (min-width: 1024px)' }
},
defaultCondition: 'mobile',
properties: {
display: ['none', 'block', 'flex'],
flexDirection: ['row', 'column'],
padding: space
// etc.
}
});
const colorProperties = defineProperties({
conditions: {
lightMode: {
'@media': '(prefers-color-scheme: light)'
},
darkMode: { '@media': '(prefers-color-scheme: dark)' }
},
defaultCondition: false,
properties: {
color: colors,
background: colors
}
// etc.
});
export const sprinkles = createSprinkles(
responsiveProperties,
colorProperties
); // src/index.ts
import { sprinkles } from "./sprinkles.css";
export const buttonStyles = sprinkles({
color: "blue50",
}); // esbuild.build.js
const { vanillaExtractPlugin } = require('@vanilla-extract/esbuild-plugin');
require('esbuild')
.build({
entryPoints: ['src/index.ts'],
bundle: true,
plugins: [vanillaExtractPlugin()],
outfile: 'dist/bundle.js',
})
.catch(() => process.exit(1)) The output was 6.8kb bundle.css & 9.6kb bundle.js. I didn't expect it to be zero-runtime, but was surprised to see that js bundle is bigger than css one. I'm wondering what |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey Bud, You are building with |
Beta Was this translation helpful? Give feedback.
-
Hey, thank you for a fast reply (and for a hard work to you all for creating such an awesome lib) On the topic, after minification it is 1.1kb css & 2.3kb js, fair enough. My discussion, albeit phrased poorly, isn't about initial cost of
It looks like using UPDATE I was very wrong :). Forgot to create styles in *.css.ts files, rather than in index.ts. Updated sandboxes & numbers. Does it mean that the moment I import |
Beta Was this translation helpful? Give feedback.
Hey Bud,
You are building with
minify
turned off, so most of the bundle size you're seeing is code that is only intended for development builds. With minify enabled the bundle size will decrease dramatically. There's still a small cost to shipping Sprinkles but I don't think it's a significant one.