Skip to content
Merged
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: 4 additions & 1 deletion packages/webpack-plugin/lib/wxss/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里走原始的stringifyRequest就可以了吧

isStatic: true,
issuerResource: this.resource,
Expand Down Expand Up @@ -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)

Expand Down
9 changes: 7 additions & 2 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 @@ -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`
}
}
}

Expand Down