Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:修改部分高级语法 #1246

Merged
merged 4 commits into from
Jul 28, 2023
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
6 changes: 3 additions & 3 deletions packages/webpack-plugin/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ class MpxWebpackPlugin {
useRelativePath: this.options.useRelativePath,
removedChunks: [],
forceProxyEventRules: this.options.forceProxyEventRules,
enableAliRequireAsync: this.options.enableAliRequireAsync,
enableRequireAsync: this.options.mode === 'wx' || (this.options.mode === 'ali' && this.options.enableAliRequireAsync),
pathHash: (resourcePath) => {
if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
return hash(path.relative(this.options.projectRoot, resourcePath))
Expand Down Expand Up @@ -1003,8 +1003,8 @@ class MpxWebpackPlugin {
if (queryObj.root) {
// 删除root query
request = addQuery(request, {}, false, ['root'])
// 目前仅wx支持require.async,其余平台使用CommonJsAsyncDependency进行模拟抹平
if (mpx.mode === 'wx' || (mpx.mode === 'ali' && mpx.enableAliRequireAsync)) {
// 目前仅wx和ali支持require.async,ali需要开启enableAliRequireAsync,其余平台使用CommonJsAsyncDependency进行模拟抹平
if (mpx.enableRequireAsync) {
const dep = new DynamicEntryDependency(request, 'export', '', queryObj.root, '', context, range, {
isRequireAsync: true,
retryRequireAsync: !!this.options.retryRequireAsync
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack-plugin/lib/json-compiler/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
const pathHash = mpx.pathHash
const getOutputPath = mpx.getOutputPath
const mode = mpx.mode
const enableAliRequireAsync = mpx.enableAliRequireAsync
const enableRequireAsync = mpx.enableRequireAsync

const isUrlRequest = r => isUrlRequestRaw(r, root, externals)
const urlToRequest = r => loaderUtils.urlToRequest(r)
Expand Down Expand Up @@ -54,7 +54,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
// 删除root query
resource = addQuery(resource, {}, false, ['root'])
// 目前只有微信支持分包异步化
if (mode === 'wx' || (mode === 'ali' && enableAliRequireAsync)) tarRoot = queryObj.root
if (enableRequireAsync) tarRoot = queryObj.root
}
const parsed = path.parse(resourcePath)
const ext = parsed.ext
Expand Down
20 changes: 11 additions & 9 deletions packages/webpack-plugin/lib/json-compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ module.exports = function (content) {
}

// 校验异步组件占位符 componentPlaceholder 不为空
const { usingComponents, componentPlaceholder = {} } = json
if (usingComponents) {
for (const compName in usingComponents) {
const compPath = usingComponents[compName]
if (!/\?root=/g.test(compPath)) continue
const compPlaceholder = componentPlaceholder[compName]
if (!compPlaceholder) {
const errMsg = `componentPlaceholder of "${compName}" doesn't exist! \n\r`
emitError(errMsg)
if (mpx.enableRequireAsync) {
const { usingComponents, componentPlaceholder = {} } = json
if (usingComponents) {
for (const compName in usingComponents) {
const compPath = usingComponents[compName]
if (!/\?root=/g.test(compPath)) continue
const compPlaceholder = componentPlaceholder[compName]
if (!compPlaceholder) {
const errMsg = `componentPlaceholder of "${compName}" doesn't exist! \n\r`
emitError(errMsg)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
const normalize = require('./normalize')
const selectorPath = normalize.lib('selector.js')
const scriptSetupPath = normalize.lib('script-setup-compiler/index.js')
const mpxLoaderPath = normalize.lib('loader.js')
const { has } = require('./set')

const tsLoaderWatchRunFilterLoaders = new Set([
selectorPath,
scriptSetupPath,
mpxLoaderPath,
'node_modules/vue-loader/lib/index.js'
])

module.exports = (loaders, loaderIndex) => {
for (let len = loaders.length; len > 0; --len) {
const currentLoader = loaders[len - 1]
if (!has(tsLoaderWatchRunFilterLoaders, filterLoaderPath => currentLoader.path.endsWith(filterLoaderPath))) {
if (currentLoader.path.endsWith('ts-loader/dist/stringify-loader.js')) {
break
}
loaderIndex--
Expand Down
18 changes: 8 additions & 10 deletions packages/webpack-plugin/lib/wxss/runtime/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Author Tobias Koppers @sokra
*/
module.exports = function (cssWithMappingToString) {
const list = []
var list = []

// return the list of modules as css string
list.toString = function toString () {
Expand All @@ -13,15 +13,15 @@ module.exports = function (cssWithMappingToString) {
var needLayer = typeof item[5] !== 'undefined'

if (item[4]) {
content += `@supports (${item[4]}) {`
content += '@supports (' + item[4] + ') {'
}

if (item[2]) {
content += `@media ${item[2]} {`
content += '@media ' + item[2] + '{'
}

if (needLayer) {
content += `@layer${item[5].length > 0 ? ` ${item[5]}` : ''} {`
content += '@layer' + (item[5].length > 0 ? item[5] : '') + '{'
}

content += cssWithMappingToString(item)
Expand Down Expand Up @@ -71,9 +71,7 @@ module.exports = function (cssWithMappingToString) {
if (typeof item[5] === 'undefined') {
item[5] = layer
} else {
item[1] = `@layer${item[5].length > 0 ? ` ${item[5]}` : ''} {${
item[1]
}}`
item[1] = '@layer' + (item[5].length > 0 ? item[5] : '') + '{' + item[1] + '}'
item[5] = layer
}
}
Expand All @@ -82,16 +80,16 @@ module.exports = function (cssWithMappingToString) {
if (!item[2]) {
item[2] = media
} else {
item[1] = `@media ${item[2]} {${item[1]}}`
item[1] = '@media' + item[2] + item[1]
item[2] = media
}
}

if (supports) {
if (!item[4]) {
item[4] = `${supports}`
item[4] = String(supports)
} else {
item[1] = `@supports (${item[4]}) {${item[1]}}`
item[1] = '@supports (' + item[4] + ')' + '{' + item[1] + '}'
item[4] = supports
}
}
Expand Down
Loading