Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/webpack-plugin/lib/wxss/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ module.exports = async function loader (content, map, meta) {
return getRequestString('styles', { src: url }, {
isStatic: true,
issuerResource: this.resource,
fromImport: true
fromImport: true,
...(isRN ? { extract: false } : {})
})
}
})
Expand Down Expand Up @@ -257,7 +258,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)

Expand Down
11 changes: 8 additions & 3 deletions packages/webpack-plugin/lib/wxss/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ function getModuleCode (
api,
replacements,
options,
isRN,
loaderContext
) {
if (options.modules.exportOnlyLocals === true) {
Expand Down Expand Up @@ -1052,10 +1053,14 @@ function getModuleCode (
`@import url(${url});`
)}${printedParam.length > 0 ? `, ${printedParam}` : ''}]);\n`
} 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 {
const otherParams = hasParams ? printedParam : ''
beforeCode += `___CSS_LOADER_EXPORT___.push([module.id, '@import "' + ${item.importName} + '";', ${JSON.stringify(otherParams)} ]);\n`
}
}
}

Expand Down
Loading