1
1
import { DefinePlugin , Configuration } from 'webpack'
2
+ import { VanillaExtractPlugin } from '@vanilla-extract/webpack-plugin'
2
3
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
3
4
import { getMode , getPath } from './utils'
4
5
import merge from 'webpack-merge'
@@ -13,7 +14,12 @@ export function webpackDefaults(config: Configuration): Configuration {
13
14
mode,
14
15
devtool : isProduction ? 'source-map' : 'inline-source-map' ,
15
16
module : {
16
- rules : [ tsRule ( ) , cssRule ( isWeb ) , fileRule ( isWeb ) ] ,
17
+ rules : [
18
+ tsRule ( ) ,
19
+ vanillaExtractRule ( ) ,
20
+ cssRule ( isWeb ) ,
21
+ fileRule ( isWeb ) ,
22
+ ] ,
17
23
} ,
18
24
resolve : {
19
25
extensions : [ '.tsx' , '.ts' , '.js' , '.json' ] ,
@@ -22,6 +28,7 @@ export function webpackDefaults(config: Configuration): Configuration {
22
28
} ,
23
29
} ,
24
30
plugins : [
31
+ new VanillaExtractPlugin ( ) ,
25
32
new MiniCssExtractPlugin (
26
33
isProduction
27
34
? {
@@ -54,7 +61,7 @@ function tsRule() {
54
61
} ,
55
62
} ,
56
63
] ,
57
- exclude : / n o d e _ m o d u l e s / ,
64
+ exclude : [ / n o d e _ m o d u l e s / , / \. c s s \. t s $ / i ] ,
58
65
}
59
66
}
60
67
@@ -84,6 +91,22 @@ function cssRule(isWeb: boolean) {
84
91
} ,
85
92
{ use : nyancssLoaders } ,
86
93
] ,
94
+ exclude : [ / \. v a n i l l a \. c s s $ / i] ,
95
+ }
96
+ }
97
+
98
+ function vanillaExtractRule ( ) {
99
+ return {
100
+ test : / \. v a n i l l a \. c s s $ / i, // Targets only CSS files generated by vanilla-extract
101
+ use : [
102
+ MiniCssExtractPlugin . loader ,
103
+ {
104
+ loader : require . resolve ( 'css-loader' ) ,
105
+ options : {
106
+ url : false , // Required as image imports should be handled via JS/TS import statements
107
+ } ,
108
+ } ,
109
+ ] ,
87
110
}
88
111
}
89
112
0 commit comments