diff --git a/packages/webpack-plugin/lib/wxss/loader.js b/packages/webpack-plugin/lib/wxss/loader.js index 024e64e49e..f9828d8924 100644 --- a/packages/webpack-plugin/lib/wxss/loader.js +++ b/packages/webpack-plugin/lib/wxss/loader.js @@ -92,6 +92,9 @@ module.exports = async function loader (content, map, meta) { filter: options.import.filter, urlHandler: (url) => { url = combineRequests(getPreRequester(this)(options.importLoaders), url) + if (isRN) { + return stringifyRequest(this, url) + } return getRequestString('styles', { src: url }, { isStatic: true, issuerResource: this.resource, @@ -249,7 +252,7 @@ module.exports = async function loader (content, map, meta) { let moduleCode try { - moduleCode = getModuleCode(result, api, replacements, options, this) + moduleCode = getModuleCode(result, api, replacements, options, isRN, this) } catch (error) { callback(error) diff --git a/packages/webpack-plugin/lib/wxss/utils.js b/packages/webpack-plugin/lib/wxss/utils.js index 180a3e1b6a..aadef53a8a 100644 --- a/packages/webpack-plugin/lib/wxss/utils.js +++ b/packages/webpack-plugin/lib/wxss/utils.js @@ -1016,6 +1016,7 @@ function getModuleCode ( api, replacements, options, + isRN, loaderContext ) { if (options.modules.exportOnlyLocals === true) { @@ -1054,8 +1055,12 @@ function getModuleCode ( } else { // 符合css后缀名的文件经过mpx处理后会带上相应的后缀防止使用 webpack 的默认解析规则,此时 require/import 相应路径时,导出的不是一段 css 代码了,事实上是一个文件路径。 const printedParam = printParams(media, dedupe, supports, layer) - const otherParams = printedParam.length > 0 ? printedParam : '' - beforeCode += `___CSS_LOADER_EXPORT___.push([module.id, '@import "' + ${item.importName} + '";', ${JSON.stringify(otherParams)} ]);\n` + const hasParams = printedParam.length > 0 + if (isRN) { + beforeCode += `___CSS_LOADER_EXPORT___.i(${item.importName}${hasParams ? `, ${printedParam}` : ''});\n` + } else { + beforeCode += `___CSS_LOADER_EXPORT___.push([module.id, '@import "' + ${item.importName} + '";'${hasParams ? `, ${printedParam}` : ''}]);\n` + } } }