Skip to content

Commit

Permalink
Merge branch 'master' into fix-web-view-refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki committed Jun 19, 2024
2 parents 2e20530 + ac36fe8 commit 7f0ecff
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"packages": [
"packages/*"
],
"version": "2.9.34"
"version": "2.9.35"
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mpxjs/core",
"version": "2.9.33",
"version": "2.9.35",
"description": "mpx runtime core",
"keywords": [
"miniprogram",
Expand Down
2 changes: 1 addition & 1 deletion packages/store/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type DepsSymbol = typeof DEPS_SYMBOL
type StateSymbol = typeof STATE_SYMBOL
type GettersSymbol = typeof GETTERS_SYMBOL

interface Store<S = {}, G = {}, M = {}, A = {}, D extends Deps = {}> {
export interface Store<S = {}, G = {}, M = {}, A = {}, D extends Deps = {}> {

[DEPS_SYMBOL]: D
[STATE_SYMBOL]: S
Expand Down
2 changes: 1 addition & 1 deletion packages/unocss-base/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mpxjs/unocss-base",
"description": "mpx unocss base preset",
"version": "2.9.7",
"version": "2.9.35",
"main": "lib/index.js",
"directories": {
"lib": "lib"
Expand Down
2 changes: 1 addition & 1 deletion packages/unocss-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mpxjs/unocss-plugin",
"version": "2.9.30",
"version": "2.9.35",
"description": "mpx unocss webpack plugin",
"main": "lib/index.js",
"scripts": {
Expand Down
18 changes: 13 additions & 5 deletions packages/webpack-plugin/lib/runtime/components/web/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,17 @@ function MpxEvent (layer) {
this.addListener()
}

if (isBrowser) {
document.addEventListener('DOMContentLoaded', function () {
// eslint-disable-next-line no-new
new MpxEvent(document.body)
}, false)
export function createEvent () {
if (isBrowser && !global.__mpxCreatedEvent) {
global.__mpxCreatedEvent = true
if (document.readyState === 'complete' || document.readyState === 'interactive') {
// eslint-disable-next-line no-new
new MpxEvent(document.body)
} else {
document.addEventListener('DOMContentLoaded', function () {
// eslint-disable-next-line no-new
new MpxEvent(document.body)
}, false)
}
}
}
3 changes: 3 additions & 0 deletions packages/webpack-plugin/lib/runtime/optionProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { hasOwn, isEmptyObject } from './utils'
import { isBrowser } from './env'
import transRpxStyle from './transRpxStyle'
import animation from './animation'
import { createEvent } from './components/web/event'

createEvent()

export function processComponentOption (
{
Expand Down
4 changes: 1 addition & 3 deletions packages/webpack-plugin/lib/web/processMainScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const addQuery = require('../utils/add-query')
const normalize = require('../utils/normalize')
const optionProcessorPath = normalize.lib('runtime/optionProcessor')
const eventPath = normalize.lib('runtime/components/web/event')

const {
buildComponentsMap,
buildPagesMap,
Expand Down Expand Up @@ -66,8 +66,6 @@ module.exports = function (script, {
globalTabBar
})

output += `\n require(${stringifyRequest(loaderContext, eventPath)})\n`

output += `\n var App = require(${stringifyRequest(loaderContext, addQuery(resource, { isApp: true }))}).default\n`

output += `
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack-plugin/lib/web/processScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function (script, {
wxsModuleMap,
localComponentsMap
}, callback) {
const { projectRoot, appInfo } = loaderContext.getMpx()
const { projectRoot, appInfo, webConfig } = loaderContext.getMpx()

const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)

Expand Down Expand Up @@ -73,7 +73,7 @@ module.exports = function (script, {
})
}

content += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction })
content += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, webConfig, hasApp })
content += getRequireScript({ ctorType, script, loaderContext })
content += `
export default processComponentOption({
Expand Down
2 changes: 2 additions & 0 deletions packages/webpack-plugin/lib/web/processTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = function (template, {
const mpx = loaderContext.getMpx()
const {
mode,
env,
defs,
wxsContentMap,
decodeHTMLText,
Expand Down Expand Up @@ -77,6 +78,7 @@ module.exports = function (template, {
isComponent: ctorType === 'component',
isPage: ctorType === 'page',
mode,
env,
srcMode: templateSrcMode,
defs,
decodeHTMLText,
Expand Down
8 changes: 7 additions & 1 deletion packages/webpack-plugin/lib/web/script-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ function buildGlobalParams ({
jsonConfig,
webConfig,
isMain,
globalTabBar
globalTabBar,
hasApp
}) {
let content = ''
if (isMain) {
Expand Down Expand Up @@ -175,6 +176,11 @@ function buildGlobalParams ({
if (globalTabBar) {
content += globalTabBar
}
} else if (!hasApp) {
content += `
global.__mpxGenericsMap = global.__mpxGenericsMap || {}
global.__mpxOptionsMap = global.__mpxOptionsMap || {}
global.__mpxTransRpxFn = ${webConfig.transRpxFn} \n`
}
content += ` global.currentModuleId = ${JSON.stringify(moduleId)}\n`
content += ` global.currentSrcMode = ${JSON.stringify(scriptSrcMode)}\n`
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mpxjs/webpack-plugin",
"version": "2.9.34",
"version": "2.9.35",
"description": "mpx compile core",
"keywords": [
"mpx"
Expand Down

0 comments on commit 7f0ecff

Please sign in to comment.