Skip to content

Commit 1c38d88

Browse files
meixgallen-zh
authored andcommitted
feat: make H5 compatible with mp comp and pages
1 parent 502d0fe commit 1c38d88

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

packages/mars-build/src/compiler/script/babel-plugin-script.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ const getPropertyVisitor = (t, options) => {
5151

5252
if (propName === 'config') {
5353
const configValue = getPlainObjectNodeValue(path.node.value, path, t) || {};
54+
55+
if (options.isApp) {
56+
if (configValue.pages) {
57+
configValue.pages = configValue.pages.map(item => item.replace(/\.(swan|mp)$/, ''));
58+
}
59+
if (configValue.tabBar && configValue.tabBar.list) {
60+
configValue.tabBar.list = configValue.tabBar.list.map(item => {
61+
item.pagePath = item.pagePath.replace(/\.(swan|mp)$/, '');
62+
return item;
63+
});
64+
}
65+
}
66+
5467
options.file && (options.file.config = configValue);
5568
path.remove();
5669
}

packages/mars-build/src/h5/transform/plugins/transformScriptPlugin.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ const Property = (t, options) => {
131131

132132
if (path.node.key.name === 'config') {
133133
const configValue = getPlainObjectNodeValue(path.node.value, path, t) || {};
134+
135+
if (configValue.pages) {
136+
configValue.pages = configValue.pages.filter(item => !/\.(swan|mp)$/.test(item));
137+
}
138+
if (configValue.tabBar && configValue.tabBar.list) {
139+
configValue.tabBar.list = configValue.tabBar.list.filter(item => !/\.(swan|mp)$/.test(item.pagePath));
140+
}
134141
options.baseOptions && (options.baseOptions.config = configValue);
135142
path.remove();
136143
}

packages/mars-build/src/scripts/defaultConfig.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ module.exports = function (target) {
88
projectFiles: ['project.swan.json', 'project.config.json'],
99
source: ['src/**/*.vue'],
1010
dest: target === 'h5' ? './dist-h5/src' : `./dist-${target}`,
11-
assets: [
11+
assets: target === 'h5' ? [
12+
'src/**/*.!(vue|swan|wxml)'
13+
]
14+
: [
1215
'src/**/*.!(vue)'
1316
],
1417
designWidth: 750,

0 commit comments

Comments
 (0)