Skip to content

Commit

Permalink
feat(themes): optimization of bundle size barrel file (#4230)
Browse files Browse the repository at this point in the history
* feat(themes): optimization of bundle size barrel file

* fix: feedback ac for direct import if three shaking is not working
  • Loading branch information
matthprost authored Sep 24, 2024
1 parent 4e2e5b5 commit b55a6e6
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-singers-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ultraviolet/themes": patch
---

Improve bundle size by removing barrel file for exporting themes
3 changes: 2 additions & 1 deletion packages/themes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ $ pnpm add @ultraviolet/ui @ultraviolet/themes @emotion/react @emotion/styled

```js
import { normalize, Button } from '@ultraviolet/ui'
import { consoleDarkTheme } from '@ultraviolet/themes' // << Here we import the theme we want to use
import { consoleDarkTheme } from '@ultraviolet/themes' // Here we import the theme we want to use
// import { consoleLightTheme } from "@ultraviolet/themes/console/light" // Alternatively you can directly import the light theme if your bundler doesn't have tree-shaking capabilities
import { Global, css, ThemeProvider } from '@emotion/react'

const App = () => (
Expand Down
5 changes: 5 additions & 0 deletions packages/themes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
},
"./console/*": {
"types": "./dist/themes/console/index.d.ts",
"require": "./dist/themes/console/index.cjs",
"default": "./dist/themes/console/index.js"
}
},
"dependencies": {
Expand Down
7 changes: 2 additions & 5 deletions packages/themes/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
export {
consoleLightTheme,
consoleDarkTheme,
consoleDarkerTheme,
} from './themes'
// eslint-disable-next-line no-restricted-syntax
export * from './themes'
File renamed without changes.
6 changes: 6 additions & 0 deletions packages/themes/src/themes/console/dark/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import deepmerge from 'deepmerge'
import { deprecatedDarkTokens } from '../deprecated/dark'
import { darkTheme } from './__generated__'

export const consoleDarkTheme: typeof darkTheme & typeof deprecatedDarkTokens =
deepmerge(darkTheme, deprecatedDarkTokens)
6 changes: 6 additions & 0 deletions packages/themes/src/themes/console/darker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import deepmerge from 'deepmerge'
import { deprecatedDarkerTokens } from '../deprecated/darker'
import { darkerTheme } from './__generated__'

export const consoleDarkerTheme: typeof darkerTheme &
typeof deprecatedDarkerTokens = deepmerge(darkerTheme, deprecatedDarkerTokens)
7 changes: 7 additions & 0 deletions packages/themes/src/themes/console/deprecated/dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
* @deprecated Those are old tokens usages and will be removed in the next major version.
*/
export const deprecatedDarkTokens = {
screens: {
xsmall: 0,
small: 576,
medium: 768,
large: 992,
xlarge: 1200,
},
colors: {
danger: {
backgroundWeak: '#151a2d',
Expand Down
7 changes: 7 additions & 0 deletions packages/themes/src/themes/console/deprecated/darker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
* @deprecated Those are old tokens usages and will be removed in the next major version.
*/
export const deprecatedDarkerTokens = {
screens: {
xsmall: 0,
small: 576,
medium: 768,
large: 992,
xlarge: 1200,
},
colors: {
danger: {
backgroundWeak: '#000000',
Expand Down
7 changes: 7 additions & 0 deletions packages/themes/src/themes/console/deprecated/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
* @deprecated Those are old tokens usages and will be removed in the next major version.
*/
export const deprecatedLightTokens = {
screens: {
xsmall: 0,
small: 576,
medium: 768,
large: 992,
xlarge: 1200,
},
colors: {
danger: {
backgroundWeak: '#ffffff',
Expand Down
33 changes: 0 additions & 33 deletions packages/themes/src/themes/console/index.ts

This file was deleted.

File renamed without changes.
6 changes: 6 additions & 0 deletions packages/themes/src/themes/console/light/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import deepmerge from 'deepmerge'
import { deprecatedLightTokens } from '../deprecated/light'
import { lightTheme } from './__generated__'

export const consoleLightTheme: typeof lightTheme &
typeof deprecatedLightTokens = deepmerge(lightTheme, deprecatedLightTokens)
8 changes: 3 additions & 5 deletions packages/themes/src/themes/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export {
consoleLightTheme,
consoleDarkTheme,
consoleDarkerTheme,
} from './console'
export { consoleLightTheme } from './console/light'
export { consoleDarkTheme } from './console/dark'
export { consoleDarkerTheme } from './console/darker'
2 changes: 1 addition & 1 deletion scripts/figma-synchronise-tokens.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export const generatePalette = (figmaTokensJson, themeMatch) => {
// For each theme
themesMatches.map(async themeMatch => {
const output = generatePalette(figmaTokensJson, themeMatch)
const filePath = `packages/themes/src/themes/console/${themeMatch.outputTheme}.ts`
const filePath = `packages/themes/src/themes/console/${themeMatch.outputTheme}/__generated__/index.ts`
await fs.writeFile(
filePath,
`${header}export const ${themeMatch.outputTheme}Theme = ${JSON.stringify(
Expand Down

0 comments on commit b55a6e6

Please sign in to comment.