Skip to content

Commit

Permalink
Merge pull request #945 from didi/fixbug-app-style-src
Browse files Browse the repository at this point in the history
修复app 中 使用 style 标签src 引入css 无filename 问题
  • Loading branch information
hiyuki authored Feb 10, 2022
2 parents 4b78885 + 579319a commit 92e22db
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/webpack-plugin/lib/extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports.pitch = async function (remainingRequest) {
const type = queryObj.type
const index = queryObj.index || 0
const isStatic = queryObj.isStatic
const issuerFile = queryObj.issuerFile
const issuerResource = queryObj.issuerResource
const fromImport = queryObj.fromImport
const needBabel = queryObj.needBabel

Expand Down Expand Up @@ -82,7 +82,8 @@ module.exports.pitch = async function (remainingRequest) {
// styles为static就两种情况,一种是.mpx中使用src引用样式,第二种为css-loader中处理@import
// 为了支持持久化缓存,.mpx中使用src引用样式对issueFile asset产生的副作用迁移到ExtractDependency中处理
case 'styles':
if (issuerFile) {
if (issuerResource) {
const issuerFile = mpx.getExtractedFile(issuerResource)
let relativePath = toPosix(path.relative(path.dirname(issuerFile), file))
relativePath = fixRelative(relativePath, mode)
if (fromImport) {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ module.exports = function (content) {
...style.src ? {
...queryObj,
isStatic: true,
issuerFile: mpx.getExtractedFile(addQuery(this.resource, { type: 'styles' }, true))
issuerResource: addQuery(this.resource, { type: 'styles' }, true)
} : null,
moduleId,
scoped
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/lib/wxml/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module.exports = function (content) {
case config[mode].wxs.tag:
// 显式传递issuerResource避免模块缓存以及提供给wxs-loader计算相对路径
extraOptions = {
issuerFile: mpx.getExtractedFile(this.resource),
issuerResource: this.resource,
isStatic: true
}
requestString = getRequestString('wxs', { src, mode: localSrcMode }, extraOptions)
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/lib/wxss/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = function (content, map) {
} else {
const requestString = getRequestString('styles', { src: imp.url }, {
isStatic: true,
issuerFile: mpx.getExtractedFile(this.resource),
issuerResource: this.resource,
fromImport: true
}, i)
return 'exports.push([module.id, ' +
Expand Down

0 comments on commit 92e22db

Please sign in to comment.