From ed34bf7888acec927ddf7cfa8ada05f6e358bd6c Mon Sep 17 00:00:00 2001 From: hejinfeng01 Date: Wed, 19 Aug 2020 21:44:51 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix(build):=201=EF=BC=9Awindows=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=8D=E6=96=9C=E6=9D=A0=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E5=87=A0=E4=B8=AA=E9=97=AE=E9=A2=98;2=EF=BC=9Aprops=E4=B8=AD?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=A8=A1=E6=9D=BF=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E4=B8=ADprops=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=80=BC=E4=BC=9A=E5=8F=98=E6=88=90"{{";=20fix(core):=201?= =?UTF-8?q?=EF=BC=9A=E4=BD=BF=E7=94=A8mixins=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E4=B8=AD=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mars-build/src/compiler/file/compileModules.js | 6 ++++-- packages/mars-build/src/gulp-mars-h5.js | 3 ++- packages/mars-build/src/swan/transform/directive/index.js | 4 +++- packages/mars-core/src/base/createComponent.js | 3 ++- packages/mars-core/src/base/createPage.js | 3 ++- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/mars-build/src/compiler/file/compileModules.js b/packages/mars-build/src/compiler/file/compileModules.js index b9f84e56..46d72c50 100644 --- a/packages/mars-build/src/compiler/file/compileModules.js +++ b/packages/mars-build/src/compiler/file/compileModules.js @@ -141,14 +141,16 @@ async function compileUIModules(uiModules, destPath) { const coreEntry = require.resolve(realName + '/mars-core', { paths: [process.cwd()] }); - const entry = coreEntry.replace('mars-core/index.js', ''); + // 获取当前操作系统的路径分隔符,否则windwos环境替换不成功 + const entry = coreEntry.replace(`mars-core${path.sep}index.js`, ''); const dest = path.resolve(destPath, modPath); const coreDestPath = path.resolve(destPath, 'mars-core'); const uiCoreDestPath = path.resolve(dest, 'mars-core'); + // 修改windows环境反斜杠为斜杠 const coreRelativePath = path.relative( uiCoreDestPath, coreDestPath - ); + ).replace(/\\/g, '/'); if (fs.existsSync(uiCoreDestPath + '/index.js')) { return; } diff --git a/packages/mars-build/src/gulp-mars-h5.js b/packages/mars-build/src/gulp-mars-h5.js index ce7fef20..77f64f6d 100644 --- a/packages/mars-build/src/gulp-mars-h5.js +++ b/packages/mars-build/src/gulp-mars-h5.js @@ -260,7 +260,8 @@ async function compile(file, opt) { } // 持续集成 main.js pageTitleMap - let filePathKey = rPath.replace(/\.vue$/, ''); + // windwos环境下的反斜杠替换为斜杠,否则输出的pageTitleMap为空 + let filePathKey = rPath.replace(/\.vue$/, '').replace(/\\/g, '/'); const isComp = config.component; if (!isComp) { pagesInfo[filePathKey] = config; diff --git a/packages/mars-build/src/swan/transform/directive/index.js b/packages/mars-build/src/swan/transform/directive/index.js index 7b97597e..9c2b4616 100644 --- a/packages/mars-build/src/swan/transform/directive/index.js +++ b/packages/mars-build/src/swan/transform/directive/index.js @@ -108,7 +108,9 @@ module.exports = function (key, value, attrs, node) { // so only bind values when is not components // if (type === 3 && !isComp) { if (type === 3) { - attrs[param] = `{{ ${value} }}`; + // 如果 mars中的 props里使用模板字符串,经过 bable转换之后 value会变成带双引号的字符串拼接 + // 导致小程序中的 props结构是双引号嵌套双引号,最终效果是该 props的值是"{{" + attrs[param] = `{{ ${value} }}`.replace(/"/g, "'"); } return true; diff --git a/packages/mars-core/src/base/createComponent.js b/packages/mars-core/src/base/createComponent.js index 615bb4e2..5321154b 100644 --- a/packages/mars-core/src/base/createComponent.js +++ b/packages/mars-core/src/base/createComponent.js @@ -11,7 +11,8 @@ import config from '../config'; export function makeVueCompCreator(getCompMixin) { return function vueCompCreator(options) { - options.mixins = [getCompMixin(options)]; + // 如果 options(vue组件的代码)中已有 mixins,则同时保留 options中的 mixins + options.mixins = (options.mixins || []).concat(getCompMixin(options)); return options; }; } diff --git a/packages/mars-core/src/base/createPage.js b/packages/mars-core/src/base/createPage.js index c48f941e..427696cc 100644 --- a/packages/mars-core/src/base/createPage.js +++ b/packages/mars-core/src/base/createPage.js @@ -75,7 +75,8 @@ export function makeCreatePage(pageMixin, {handleProxy, handleModel}, setData, c $api }) { return function (options) { - options.mixins = [pageMixin]; + // 如果 options(vue页面的代码)中已有 mixins,则同时保留 options中的 mixins + options.mixins = (options.mixins || []).concat(pageMixin); let initData = typeof options.data === 'function' ? options.data.call({ $api From eb7a0e24a3b2f406e9b81e3cf9194b337391ad6e Mon Sep 17 00:00:00 2001 From: kingphone_he Date: Thu, 5 Nov 2020 20:13:21 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9mars=E7=9A=84mixin?= =?UTF-8?q?=E4=B8=8E=E4=B8=9A=E5=8A=A1=E4=BB=A3=E7=A0=81=E4=B8=AD=E7=9A=84?= =?UTF-8?q?mixin=E7=9A=84=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mars-core/src/base/createComponent.js | 2 +- packages/mars-core/src/base/createPage.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mars-core/src/base/createComponent.js b/packages/mars-core/src/base/createComponent.js index 5321154b..8874076d 100644 --- a/packages/mars-core/src/base/createComponent.js +++ b/packages/mars-core/src/base/createComponent.js @@ -12,7 +12,7 @@ import config from '../config'; export function makeVueCompCreator(getCompMixin) { return function vueCompCreator(options) { // 如果 options(vue组件的代码)中已有 mixins,则同时保留 options中的 mixins - options.mixins = (options.mixins || []).concat(getCompMixin(options)); + options.mixins = [getCompMixin(options), ...options.mixins || []]; return options; }; } diff --git a/packages/mars-core/src/base/createPage.js b/packages/mars-core/src/base/createPage.js index 427696cc..52b2d739 100644 --- a/packages/mars-core/src/base/createPage.js +++ b/packages/mars-core/src/base/createPage.js @@ -76,7 +76,7 @@ export function makeCreatePage(pageMixin, {handleProxy, handleModel}, setData, c }) { return function (options) { // 如果 options(vue页面的代码)中已有 mixins,则同时保留 options中的 mixins - options.mixins = (options.mixins || []).concat(pageMixin); + options.mixins = [pageMixin, ...options.mixins || []]; let initData = typeof options.data === 'function' ? options.data.call({ $api From d556ceaaed2bcd5900103acdf5451c05ecfd2b75 Mon Sep 17 00:00:00 2001 From: kingphone_he Date: Thu, 5 Nov 2020 20:24:25 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9mars=E7=9A=84mixin?= =?UTF-8?q?=E4=B8=8E=E4=B8=9A=E5=8A=A1=E4=BB=A3=E7=A0=81=E4=B8=AD=E7=9A=84?= =?UTF-8?q?mixin=E7=9A=84=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mars-build/src/swan/transform/directive/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/mars-build/src/swan/transform/directive/index.js b/packages/mars-build/src/swan/transform/directive/index.js index 9c2b4616..7b97597e 100644 --- a/packages/mars-build/src/swan/transform/directive/index.js +++ b/packages/mars-build/src/swan/transform/directive/index.js @@ -108,9 +108,7 @@ module.exports = function (key, value, attrs, node) { // so only bind values when is not components // if (type === 3 && !isComp) { if (type === 3) { - // 如果 mars中的 props里使用模板字符串,经过 bable转换之后 value会变成带双引号的字符串拼接 - // 导致小程序中的 props结构是双引号嵌套双引号,最终效果是该 props的值是"{{" - attrs[param] = `{{ ${value} }}`.replace(/"/g, "'"); + attrs[param] = `{{ ${value} }}`; } return true;