1+ // @ts -check
2+
13/*
24 MIT License http://www.opensource.org/licenses/mit-license.php
35 Author Tobias Koppers @sokra
46 Modified by Evan You @yyx990803
57*/
68
9+ /**
10+ * @typedef {{manualInject?: boolean; shadowMode?: boolean; ssrId?: string} } LoaderOptions
11+ * @typedef {import('webpack').LoaderContext<LoaderOptions> } LoaderContext
12+ */
13+
714const path = require ( 'node:path' )
815const qs = require ( 'node:querystring' )
916
@@ -13,28 +20,45 @@ const loaderUtils = require('loader-utils')
1320// eslint-disable-next-line no-empty-function
1421module . exports = function ( ) { }
1522
23+ /**
24+ * @param {LoaderContext } loaderContext
25+ * @param {string } request
26+ * @returns {string } stringified request
27+ */
28+ const stringifyRequest = ( loaderContext , request ) =>
29+ loaderContext . utils
30+ ? JSON . stringify (
31+ loaderContext . utils . contextify ( loaderContext . context , request ) ,
32+ )
33+ : loaderUtils . stringifyRequest ( loaderContext , request )
34+
35+ /**
36+ * @this {LoaderContext & {minimize?: boolean}}
37+ * @param {string } remainingRequest
38+ * @returns {string } transformed codes
39+ */
1640module . exports . pitch = function ( remainingRequest ) {
1741 const isServer = this . target === 'node'
1842 const isProduction = this . minimize || process . env . NODE_ENV === 'production'
19- const addStylesClientPath = loaderUtils . stringifyRequest (
43+ const addStylesClientPath = stringifyRequest (
2044 this ,
2145 '!' + path . join ( __dirname , 'lib/addStylesClient.js' ) ,
2246 )
23- const addStylesServerPath = loaderUtils . stringifyRequest (
47+ const addStylesServerPath = stringifyRequest (
2448 this ,
2549 '!' + path . join ( __dirname , 'lib/addStylesServer.js' ) ,
2650 )
27- const addStylesShadowPath = loaderUtils . stringifyRequest (
51+ const addStylesShadowPath = stringifyRequest (
2852 this ,
2953 '!' + path . join ( __dirname , 'lib/addStylesShadow.js' ) ,
3054 )
3155
32- const request = loaderUtils . stringifyRequest ( this , '!!' + remainingRequest )
56+ const request = stringifyRequest ( this , '!!' + remainingRequest )
3357 const relPath = path
3458 . relative ( __dirname , this . resourcePath )
3559 . replaceAll ( '\\' , '/' )
3660 const id = JSON . stringify ( hash ( request + relPath ) )
37- const options = loaderUtils . getOptions ( this ) || { }
61+ const options = this . getOptions ?. ( ) || loaderUtils . getOptions ( this ) || { }
3862
3963 // direct css import from js --> direct, or manually call `styles.__inject__(ssrContext)` with `manualInject` option
4064 // css import from react file --> component lifecycle linked
0 commit comments