Skip to content

Commit 77c6ad4

Browse files
authored
fix(app, protocol-designer, opentrons-ai-client, components): fix build issue with css module files (#18930)
* fix(app, protocol-designer, opentrons-ai-client, components): fix build issue with css module files
1 parent bde213a commit 77c6ad4

File tree

8 files changed

+107
-7
lines changed

8 files changed

+107
-7
lines changed

app/cssModuleSideEffect.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { Plugin } from 'vite'
2+
3+
/**
4+
* Plugin to make sure CSS modules do not get tree shaked out of the dist.
5+
* see https://github.com/vitejs/vite/pull/16051
6+
*
7+
* @returns {Plugin} The Vite plugin object.
8+
*/
9+
10+
export const cssModuleSideEffect = (): Plugin => {
11+
return {
12+
name: 'css-module-side-effectful',
13+
enforce: 'post',
14+
transform(_: string, id: string) {
15+
if (id.includes('.module.')) {
16+
return {
17+
moduleSideEffects: 'no-treeshake', // or true, which also works with slightly better treeshake
18+
}
19+
}
20+
},
21+
}
22+
}

app/vite.config.mts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import path from 'path'
2-
import { defineConfig } from 'vite'
32
import react from '@vitejs/plugin-react'
4-
import postCssImport from 'postcss-import'
3+
import lostCss from 'lost'
54
import postCssApply from 'postcss-apply'
65
import postColorModFunction from 'postcss-color-mod-function'
6+
import postCssImport from 'postcss-import'
77
import postCssPresetEnv from 'postcss-preset-env'
8-
import lostCss from 'lost'
8+
import { defineConfig } from 'vite'
9+
910
import { versionForProject } from '../scripts/git-version.mjs'
11+
import { cssModuleSideEffect } from './cssModuleSideEffect'
12+
1013
import type { UserConfig } from 'vite'
1114

1215
export default defineConfig(
@@ -19,7 +22,7 @@ export default defineConfig(
1922
build: {
2023
// Relative to the root
2124
outDir: 'dist',
22-
sourcemap: true
25+
sourcemap: true,
2326
},
2427
plugins: [
2528
react({
@@ -29,6 +32,7 @@ export default defineConfig(
2932
configFile: true,
3033
},
3134
}),
35+
cssModuleSideEffect(),
3236
],
3337
optimizeDeps: {
3438
esbuildOptions: {

components/cssModuleSideEffect.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { Plugin } from 'vite'
2+
3+
/**
4+
* Plugin to make sure CSS modules do not get tree shaked out of the dist.
5+
* see https://github.com/vitejs/vite/pull/16051
6+
*
7+
* @returns {Plugin} The Vite plugin object.
8+
*/
9+
10+
export const cssModuleSideEffect = (): Plugin => {
11+
return {
12+
name: 'css-module-side-effectful',
13+
enforce: 'post',
14+
transform(_: string, id: string) {
15+
if (id.includes('.module.')) {
16+
return {
17+
moduleSideEffects: 'no-treeshake', // or true, which also works with slightly better treeshake
18+
}
19+
}
20+
},
21+
}
22+
}

components/vite.config.mts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import path from 'path'
2-
import { defineConfig } from 'vite'
32
import react from '@vitejs/plugin-react'
4-
import postCssImport from 'postcss-import'
3+
import lostCss from 'lost'
54
import postCssApply from 'postcss-apply'
65
import postColorModFunction from 'postcss-color-mod-function'
6+
import postCssImport from 'postcss-import'
77
import postCssPresetEnv from 'postcss-preset-env'
8-
import lostCss from 'lost'
8+
import { defineConfig } from 'vite'
9+
10+
import { cssModuleSideEffect } from './cssModuleSideEffect'
911

1012
export default defineConfig({
1113
build: {
@@ -31,6 +33,7 @@ export default defineConfig({
3133
configFile: true,
3234
},
3335
}),
36+
cssModuleSideEffect(),
3437
],
3538
optimizeDeps: {
3639
esbuildOptions: {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { Plugin } from 'vite'
2+
3+
/**
4+
* Plugin to make sure CSS modules do not get tree shaked out of the dist.
5+
* see https://github.com/vitejs/vite/pull/16051
6+
*
7+
* @returns {Plugin} The Vite plugin object.
8+
*/
9+
10+
export const cssModuleSideEffect = (): Plugin => {
11+
return {
12+
name: 'css-module-side-effectful',
13+
enforce: 'post',
14+
transform(_: string, id: string) {
15+
if (id.includes('.module.')) {
16+
return {
17+
moduleSideEffects: 'no-treeshake', // or true, which also works with slightly better treeshake
18+
}
19+
}
20+
},
21+
}
22+
}

opentrons-ai-client/vite.config.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import postCssImport from 'postcss-import'
77
import postCssPresetEnv from 'postcss-preset-env'
88
import { defineConfig } from 'vite'
99

10+
import { cssModuleSideEffect } from './cssModuleSideEffect'
11+
1012
export default defineConfig({
1113
// this makes imports relative rather than absolute
1214
base: '',
@@ -22,6 +24,7 @@ export default defineConfig({
2224
configFile: true,
2325
},
2426
}),
27+
cssModuleSideEffect(),
2528
],
2629
optimizeDeps: {
2730
esbuildOptions: {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { Plugin } from 'vite'
2+
3+
/**
4+
* Plugin to make sure CSS modules do not get tree shaked out of the dist.
5+
* see https://github.com/vitejs/vite/pull/16051
6+
*
7+
* @returns {Plugin} The Vite plugin object.
8+
*/
9+
10+
export const cssModuleSideEffect = (): Plugin => {
11+
return {
12+
name: 'css-module-side-effectful',
13+
enforce: 'post',
14+
transform(_: string, id: string) {
15+
if (id.includes('.module.')) {
16+
return {
17+
moduleSideEffects: 'no-treeshake', // or true, which also works with slightly better treeshake
18+
}
19+
}
20+
},
21+
}
22+
}

protocol-designer/vite.config.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import postCssPresetEnv from 'postcss-preset-env'
99
import { defineConfig } from 'vite'
1010

1111
import { versionForProject } from '../scripts/git-version.mjs'
12+
import { cssModuleSideEffect } from './cssModuleSideEffect'
1213

1314
import type { UserConfig } from 'vite'
1415

@@ -35,6 +36,7 @@ export default defineConfig(
3536
configFile: true,
3637
},
3738
}),
39+
cssModuleSideEffect(),
3840
{
3941
name: 'markdown-loader',
4042
transform(code, id) {

0 commit comments

Comments
 (0)