@@ -1059,6 +1059,147 @@ describe('"minify" option', () => {
1059
1059
expect ( getWarnings ( stats ) ) . toMatchSnapshot ( "warning" ) ;
1060
1060
} ) ;
1061
1061
1062
+ it ( 'should work with "CssMinimizerPlugin.swcMinify" minifier' , async ( ) => {
1063
+ const compiler = getCompiler ( {
1064
+ entry : {
1065
+ foo : `${ __dirname } /fixtures/sourcemap/foo.scss` ,
1066
+ } ,
1067
+ module : {
1068
+ rules : [
1069
+ {
1070
+ test : / .s ? c s s $ / i,
1071
+ use : [
1072
+ MiniCssExtractPlugin . loader ,
1073
+ { loader : "css-loader" , options : { sourceMap : true } } ,
1074
+ { loader : "sass-loader" , options : { sourceMap : true } } ,
1075
+ ] ,
1076
+ } ,
1077
+ ] ,
1078
+ } ,
1079
+ } ) ;
1080
+
1081
+ new CssMinimizerPlugin ( {
1082
+ minimizerOptions : { } ,
1083
+ minify : [ CssMinimizerPlugin . swcMinify ] ,
1084
+ } ) . apply ( compiler ) ;
1085
+
1086
+ const stats = await compile ( compiler ) ;
1087
+
1088
+ expect ( readAssets ( compiler , stats , / \. c s s ( \. m a p ) ? $ / ) ) . toMatchSnapshot (
1089
+ "assets"
1090
+ ) ;
1091
+ expect ( getErrors ( stats ) ) . toMatchSnapshot ( "error" ) ;
1092
+ expect ( getWarnings ( stats ) ) . toMatchSnapshot ( "warning" ) ;
1093
+ } ) ;
1094
+
1095
+ // Need improve package for source map generation
1096
+ it ( 'should work with "CssMinimizerPlugin.swcMinify" minifier and generate source maps' , async ( ) => {
1097
+ const compiler = getCompiler ( {
1098
+ devtool : "source-map" ,
1099
+ entry : {
1100
+ foo : `${ __dirname } /fixtures/sourcemap/foo.scss` ,
1101
+ } ,
1102
+ module : {
1103
+ rules : [
1104
+ {
1105
+ test : / .s ? c s s $ / i,
1106
+ use : [
1107
+ MiniCssExtractPlugin . loader ,
1108
+ { loader : "css-loader" , options : { sourceMap : true } } ,
1109
+ { loader : "sass-loader" , options : { sourceMap : true } } ,
1110
+ ] ,
1111
+ } ,
1112
+ ] ,
1113
+ } ,
1114
+ } ) ;
1115
+
1116
+ new CssMinimizerPlugin ( {
1117
+ minimizerOptions : { } ,
1118
+ minify : [ CssMinimizerPlugin . swcMinify ] ,
1119
+ } ) . apply ( compiler ) ;
1120
+
1121
+ const stats = await compile ( compiler ) ;
1122
+
1123
+ expect ( readAssets ( compiler , stats , / \. c s s ( \. m a p ) ? $ / ) ) . toMatchSnapshot (
1124
+ "assets"
1125
+ ) ;
1126
+ expect ( getErrors ( stats ) ) . toMatchSnapshot ( "error" ) ;
1127
+ expect ( getWarnings ( stats ) ) . toMatchSnapshot ( "warning" ) ;
1128
+ } ) ;
1129
+
1130
+ it ( 'should work with "CssMinimizerPlugin.swcMinify" minifier and generate source maps #2' , async ( ) => {
1131
+ const compiler = getCompiler ( {
1132
+ devtool : "source-map" ,
1133
+ entry : {
1134
+ foo : `${ __dirname } /fixtures/sourcemap/foo.scss` ,
1135
+ } ,
1136
+ module : {
1137
+ rules : [
1138
+ {
1139
+ test : / .s ? c s s $ / i,
1140
+ use : [
1141
+ MiniCssExtractPlugin . loader ,
1142
+ { loader : "css-loader" , options : { sourceMap : true } } ,
1143
+ { loader : "sass-loader" , options : { sourceMap : true } } ,
1144
+ ] ,
1145
+ } ,
1146
+ ] ,
1147
+ } ,
1148
+ plugins : [
1149
+ new MiniCssExtractPlugin ( {
1150
+ filename : "foo/[name].css" ,
1151
+ chunkFilename : "foo/[id].[name].css" ,
1152
+ } ) ,
1153
+ ] ,
1154
+ } ) ;
1155
+
1156
+ new CssMinimizerPlugin ( {
1157
+ minimizerOptions : { } ,
1158
+ minify : [ CssMinimizerPlugin . swcMinify ] ,
1159
+ } ) . apply ( compiler ) ;
1160
+
1161
+ const stats = await compile ( compiler ) ;
1162
+
1163
+ expect ( readAssets ( compiler , stats , / \. c s s ( \. m a p ) ? $ / ) ) . toMatchSnapshot (
1164
+ "assets"
1165
+ ) ;
1166
+ expect ( getErrors ( stats ) ) . toMatchSnapshot ( "error" ) ;
1167
+ expect ( getWarnings ( stats ) ) . toMatchSnapshot ( "warning" ) ;
1168
+ } ) ;
1169
+
1170
+ // TODO improve test when options will come
1171
+ it ( 'should work with "CssMinimizerPlugin.swcMinify" minifier and options for "swcMinify"' , async ( ) => {
1172
+ const compiler = getCompiler ( {
1173
+ entry : {
1174
+ foo : `${ __dirname } /fixtures/nesting.css` ,
1175
+ } ,
1176
+ module : {
1177
+ rules : [
1178
+ {
1179
+ test : / \. c s s $ / i,
1180
+ use : [
1181
+ MiniCssExtractPlugin . loader ,
1182
+ { loader : "css-loader" , options : { sourceMap : true } } ,
1183
+ ] ,
1184
+ } ,
1185
+ ] ,
1186
+ } ,
1187
+ } ) ;
1188
+
1189
+ new CssMinimizerPlugin ( {
1190
+ minimizerOptions : { } ,
1191
+ minify : [ CssMinimizerPlugin . swcMinify ] ,
1192
+ } ) . apply ( compiler ) ;
1193
+
1194
+ const stats = await compile ( compiler ) ;
1195
+
1196
+ expect ( readAssets ( compiler , stats , / \. c s s ( \. m a p ) ? $ / ) ) . toMatchSnapshot (
1197
+ "assets"
1198
+ ) ;
1199
+ expect ( getErrors ( stats ) ) . toMatchSnapshot ( "error" ) ;
1200
+ expect ( getWarnings ( stats ) ) . toMatchSnapshot ( "warning" ) ;
1201
+ } ) ;
1202
+
1062
1203
it ( "should work throw an error if minimizer function doesn't return" , async ( ) => {
1063
1204
const compiler = getCompiler ( {
1064
1205
entry : {
0 commit comments