Skip to content

Commit

Permalink
fix(labware-library): fix labware-library css issue (#16502)
Browse files Browse the repository at this point in the history
* fix(labware-library): fix labware-library css issue
  • Loading branch information
koji authored and TamarZanzouri committed Oct 18, 2024
1 parent 0b977af commit 27a8768
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions labware-library/cssModuleSideEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Plugin } from 'vite'

/**
* Plugin to make sure CSS modules do not get tree shaked out of the dist.
* see https://github.com/vitejs/vite/pull/16051
*
* @returns {Plugin} The Vite plugin object.
*/

export const cssModuleSideEffect = (): Plugin => {
return {
name: 'css-module-side-effectful',
enforce: 'post',
transform(_: string, id: string) {
if (id.includes('.module.')) {
return {
moduleSideEffects: 'no-treeshake', // or true, which also works with slightly better treeshake
}
}
},
}
}
2 changes: 2 additions & 0 deletions labware-library/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import postCssApply from 'postcss-apply'
import postColorModFunction from 'postcss-color-mod-function'
import postCssPresetEnv from 'postcss-preset-env'
import lostCss from 'lost'
import { cssModuleSideEffect } from './cssModuleSideEffect'

const testAliases: {} | { 'file-saver': string } =
process.env.CYPRESS === '1'
Expand Down Expand Up @@ -37,6 +38,7 @@ export default defineConfig({
configFile: true,
},
}),
cssModuleSideEffect(), // Note for treeshake
],
optimizeDeps: {
esbuildOptions: {
Expand Down

0 comments on commit 27a8768

Please sign in to comment.