@@ -13,6 +13,11 @@ import {
13
13
} from './messages'
14
14
import { getPostCssPlugins } from './plugins'
15
15
16
+ // RegExps for Stylesheets
17
+ const regexCssAll = / \. c s s $ /
18
+ const regexCssGlobal = / (?< ! \. m o d u l e ) \. c s s $ /
19
+ const regexCssModules = / \. m o d u l e \. c s s $ /
20
+
16
21
function getClientStyleLoader ( {
17
22
isDevelopment,
18
23
assetPrefix,
@@ -106,7 +111,7 @@ export const css = curry(async function css(
106
111
loader ( {
107
112
oneOf : [
108
113
{
109
- test : / \. c s s $ / ,
114
+ test : regexCssAll ,
110
115
// Use a loose regex so we don't have to crawl the file system to
111
116
// find the real file name (if present).
112
117
issuer : { test : / p a g e s [ \\ / ] _ d o c u m e n t \. / } ,
@@ -133,7 +138,7 @@ export const css = curry(async function css(
133
138
// via the `pure` mode in `css-loader`.
134
139
sideEffects : false ,
135
140
// CSS Modules are activated via this specific extension.
136
- test : / \. m o d u l e \. c s s $ / ,
141
+ test : regexCssModules ,
137
142
// CSS Modules are only supported in the user's application. We're
138
143
// not yet allowing CSS imports _within_ `node_modules`.
139
144
issuer : {
@@ -191,7 +196,7 @@ export const css = curry(async function css(
191
196
loader ( {
192
197
oneOf : [
193
198
{
194
- test : / \. m o d u l e \. c s s $ / ,
199
+ test : regexCssModules ,
195
200
use : {
196
201
loader : 'error-loader' ,
197
202
options : {
@@ -206,7 +211,9 @@ export const css = curry(async function css(
206
211
if ( ctx . isServer ) {
207
212
fns . push (
208
213
loader ( {
209
- oneOf : [ { test : / \. c s s $ / , use : require . resolve ( 'ignore-loader' ) } ] ,
214
+ oneOf : [
215
+ { test : regexCssGlobal , use : require . resolve ( 'ignore-loader' ) } ,
216
+ ] ,
210
217
} )
211
218
)
212
219
} else if ( ctx . customAppFile ) {
@@ -219,7 +226,7 @@ export const css = curry(async function css(
219
226
// no side-effects.
220
227
// See https://github.com/webpack/webpack/issues/6571
221
228
sideEffects : true ,
222
- test : / \. c s s $ / ,
229
+ test : regexCssGlobal ,
223
230
issuer : { include : ctx . customAppFile } ,
224
231
225
232
use : [
@@ -257,7 +264,7 @@ export const css = curry(async function css(
257
264
loader ( {
258
265
oneOf : [
259
266
{
260
- test : / \. c s s $ / ,
267
+ test : regexCssGlobal ,
261
268
issuer : { include : [ / n o d e _ m o d u l e s / ] } ,
262
269
use : {
263
270
loader : 'error-loader' ,
@@ -275,7 +282,7 @@ export const css = curry(async function css(
275
282
loader ( {
276
283
oneOf : [
277
284
{
278
- test : / \. c s s $ / ,
285
+ test : regexCssGlobal ,
279
286
use : {
280
287
loader : 'error-loader' ,
281
288
options : {
@@ -298,7 +305,7 @@ export const css = curry(async function css(
298
305
oneOf : [
299
306
{
300
307
// This should only be applied to CSS files
301
- issuer : { test : / \. c s s $ / } ,
308
+ issuer : { test : regexCssAll } ,
302
309
// Exclude extensions that webpack handles by default
303
310
exclude : [ / \. ( j s | m j s | j s x | t s | t s x ) $ / , / \. h t m l $ / , / \. j s o n $ / ] ,
304
311
use : {
@@ -323,12 +330,15 @@ export const css = curry(async function css(
323
330
new MiniCssExtractPlugin ( {
324
331
filename : 'static/css/[contenthash].css' ,
325
332
chunkFilename : 'static/css/[contenthash].css' ,
326
- // Next.js guarantees that CSS order doesn't matter, due to imposed
333
+ // Next.js guarantees that CSS order " doesn't matter" , due to imposed
327
334
// restrictions:
328
335
// 1. Global CSS can only be defined in a single entrypoint (_app)
329
336
// 2. CSS Modules generate scoped class names by default and cannot
330
337
// include Global CSS (:global() selector).
331
338
//
339
+ // While not a perfect guarantee (e.g. liberal use of `:global()`
340
+ // selector), this assumption is required to code-split CSS.
341
+ //
332
342
// If this warning were to trigger, it'd be unactionable by the user,
333
343
// but also not valid -- so we disable it.
334
344
ignoreOrder : true ,
0 commit comments