Skip to content

Commit

Permalink
support warnHandler && fix web mid transport
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki committed Oct 18, 2024
1 parent c117f28 commit 120abe7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Mpx.config = {
ignoreProxyWhiteList: ['id', 'dataset', 'data'],
observeClassInstance: false,
errorHandler: null,
warnHandler: null,
proxyEventHandler: null,
setDataHandler: null,
forceFlushSync: false,
Expand Down
8 changes: 7 additions & 1 deletion packages/utils/src/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ export function warn (msg, location, e) {
} else if (condition instanceof RegExp) {
ignore = condition.test(msg)
}
if (!ignore) return log('warn', msg, location, e)
if (!ignore) {
const warnHandler = global.__mpx?.config.warnHandler
if (isFunction(warnHandler)) {
warnHandler(msg, location, e)
}
return log('warn', msg, location, e)
}
}

export function error (msg, location, e) {
Expand Down
4 changes: 1 addition & 3 deletions packages/webpack-plugin/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,6 @@ try {
}

if (isWeb(mpx.mode)) {
const mpxStyleOptions = queryObj.mpxStyleOptions
const firstLoader = loaders[0] ? toPosix(loaders[0].loader) : ''
const isPitcherRequest = firstLoader.includes('node_modules/vue-loader/lib/loaders/pitcher')
let cssLoaderIndex = -1
Expand All @@ -1837,8 +1836,7 @@ try {
}
if (loaderIndex > -1) {
loaders.splice(loaderIndex + 1, 0, {
loader: styleCompilerPath,
options: (mpxStyleOptions && JSON.parse(mpxStyleOptions)) || {}
loader: styleCompilerPath
})
}
}
Expand Down
7 changes: 2 additions & 5 deletions packages/webpack-plugin/lib/web/processStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ module.exports = function (styles, options, callback) {
attrs (style) {
const attrs = Object.assign({}, style.attrs)
if (options.autoScope) attrs.scoped = true
attrs.mpxStyleOptions = JSON.stringify({
// scoped: !!options.autoScope,
// query中包含module字符串会被新版vue-cli中的默认rules当做css-module处理
mid: options.moduleId
})
// query中包含module字符串会被新版vue-cli中的默认rules当做css-module处理
attrs.mid = options.moduleId
return attrs
}
})
Expand Down

0 comments on commit 120abe7

Please sign in to comment.