Skip to content

Commit

Permalink
merged from origin
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki committed Dec 25, 2023
2 parents d2d0cff + ae26ece commit 1a88876
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Mpx是一款致力于提升小程序开发体验和用户体验的增强型小

Mpx具有以下功能特性:
* [数据响应](https://www.mpxjs.cn/guide/basic/reactive.html) (赋值响应 / [watch](https://www.mpxjs.cn/api/global-api.html#watch) / computed)
* [组合式 API](#todo link)
* [组合式 API](https://mpxjs.cn/guide/composition-api/composition-api.html)
* 增强模板语法 ([动态组件](https://www.mpxjs.cn/guide/basic/component.html#%E5%8A%A8%E6%80%81%E7%BB%84%E4%BB%B6) / [样式绑定 / 类名绑定 ](https://www.mpxjs.cn/guide/basic/class-style-binding.html#%E7%B1%BB%E5%90%8D%E7%BB%91%E5%AE%9A) / [内联事件函数](https://www.mpxjs.cn/guide/basic/event.html) / [双向绑定](https://www.mpxjs.cn/guide/basic/two-way-binding.html) / [refs](https://www.mpxjs.cn/guide/basic/refs.html))
* 极致性能 ([运行时性能优化](https://www.mpxjs.cn/guide/understand/runtime.html) / [包体积优化](https://www.mpxjs.cn/guide/understand/compile.html#%E5%88%86%E5%8C%85%E5%A4%84%E7%90%86) / 框架运行时体积14KB)
* [高效强大的编译构建](https://www.mpxjs.cn/guide/understand/compile.html#%E5%88%86%E5%8C%85%E5%A4%84%E7%90%86) (基于webpack5 / 支持持久化缓存 / 兼容webpack生态 / 兼容原生小程序 / 完善支持npm场景下的分包输出 / 高效调试)
Expand Down
3 changes: 2 additions & 1 deletion packages/webpack-plugin/lib/web/processMainScript.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// 该文件下的字符串语句需要使用 es5 语法
const addQuery = require('../utils/add-query')
const normalize = require('../utils/normalize')
const optionProcessorPath = normalize.lib('runtime/optionProcessor')
Expand Down Expand Up @@ -64,7 +65,7 @@ module.exports = function (script, {
globalTabBar
})

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

output += `
export default processAppOption({
Expand Down
20 changes: 12 additions & 8 deletions packages/webpack-plugin/lib/web/script-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ function buildPagesMap ({ localPagesMap, loaderContext, tabBar, tabBarMap, tabBa
if (pageCfg) {
const pageRequest = stringifyRequest(loaderContext, pageCfg.resource)
if (pageCfg.async) {
tabBarPagesMap[pagePath] = `()=>import(${getAsyncChunkName(pageCfg.async)}${pageRequest}).then(res => getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} }))`
tabBarPagesMap[pagePath] = `function() {
return import(${getAsyncChunkName(pageCfg.async)}${pageRequest}).then(function(res) {return getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} })});
}`
} else {
tabBarPagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
}
Expand All @@ -94,7 +96,9 @@ function buildPagesMap ({ localPagesMap, loaderContext, tabBar, tabBarMap, tabBa
pagesMap[pagePath] = `getComponent(require(${stringifyRequest(loaderContext, tabBarContainerPath)}), { __mpxBuiltIn: true })`
} else {
if (pageCfg.async) {
pagesMap[pagePath] = `()=>import(${getAsyncChunkName(pageCfg.async)} ${pageRequest}).then(res => getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} }))`
pagesMap[pagePath] = `function() {
return import(${getAsyncChunkName(pageCfg.async)} ${pageRequest}).then(function(res){ return getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} })});
}`
} else {
// 为了保持小程序中app->page->component的js执行顺序,所有的page和component都改为require引入
pagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
Expand Down Expand Up @@ -132,12 +136,12 @@ function buildGlobalParams ({ moduleId, scriptSrcMode, loaderContext, isProducti
if (!(typeof window !== 'undefined')) {
console.error('[Mpx runtime error]: Dangerous API! global.getCurrentPages is running in non browser environment, It may cause some problems, please use this method with caution')
}
const router = global.__mpxRouter
var router = global.__mpxRouter
if(!router) return []
// @ts-ignore
return (router.lastStack || router.stack).map(item => {
let page
const vnode = item.vnode
return (router.lastStack || router.stack).map(function(item){
var page
var vnode = item.vnode
if (vnode && vnode.componentInstance) {
page = vnode.tag.endsWith('mpx-tab-bar-container') ? vnode.componentInstance.$refs.tabBarPage : vnode.componentInstance
}
Expand Down Expand Up @@ -178,13 +182,13 @@ function buildI18n ({ i18n, loaderContext }) {
delete i18nObj[`${key}Path`]
}
})
i18nContent += ` const i18nCfg = ${JSON.stringify(i18nObj)}\n`
i18nContent += ` var i18nCfg = ${JSON.stringify(i18nObj)}\n`
Object.keys(requestObj).forEach((key) => {
i18nContent += ` i18nCfg.${key} = require(${requestObj[key]})\n`
})
i18nContent += `
i18nCfg.legacy = false
const i18n = createI18n(i18nCfg, VueI18n)
var i18n = createI18n(i18nCfg, VueI18n)
Vue.use(i18n)
Mpx.i18n = i18n\n`
return i18nContent
Expand Down

0 comments on commit 1a88876

Please sign in to comment.