Skip to content

Commit

Permalink
Merge pull request #3695 from alibaba/fix/windows-path
Browse files Browse the repository at this point in the history
fix(rax-app): mpa windows error
  • Loading branch information
SoloJiang authored Oct 22, 2020
2 parents ccb6345 + 72d170e commit 8d640ab
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
7 changes: 7 additions & 0 deletions packages/build-app-helpers/src/formatPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as path from 'path';

function formatPath(pathStr: string): string {
return process.platform === 'win32' ? pathStr.split(path.sep).join('/') : pathStr;
}

export default formatPath;
4 changes: 3 additions & 1 deletion packages/build-app-helpers/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import getMpaEntries from './getMpaEntries';
import getRoutesByAppJson from './getRoutesByAppJson';
import formatPath from './formatPath';

export {
getMpaEntries,
getRoutesByAppJson
getRoutesByAppJson,
formatPath,
};
3 changes: 2 additions & 1 deletion packages/build-mpa-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"fs-extra": "^8.1.0",
"loader-utils": "^2.0.0"
"loader-utils": "^2.0.0",
"build-app-helpers": "^1.0.0"
}
}
3 changes: 2 additions & 1 deletion packages/build-mpa-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path';
import { formatPath } from 'build-app-helpers';

interface IEntries {
entryName: string;
Expand Down Expand Up @@ -42,7 +43,7 @@ const setMPAConfig = (config, options: IConfigOptions) => {
config.entry(entryName).add((/app\.(t|j)sx?$/.test(entryPath) || type === 'node') ? pageEntry : `${require.resolve('./mpa-loader')}?type=${type}&framework=${framework}!${pageEntry}`);
// get page paths for rule match
const matchStr = `src/pages/${pageName}`;
matchStrs.push(process.platform === 'win32' ? matchStr.replace(/\//g, '\\\\') : matchStr);
matchStrs.push(formatPath(matchStr));
});
if (type === 'web') {
config.plugin('document').tap(args => {
Expand Down
3 changes: 2 additions & 1 deletion packages/build-mpa-config/src/mpa-loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getOptions } from 'loader-utils';
import { formatPath } from 'build-app-helpers';

function mpaLoader() {
const options = getOptions(this) || {};
Expand Down Expand Up @@ -30,7 +31,7 @@ function mpaLoader() {
}
const source = `
import { render, createElement } from '${framework}';
import Component from '${process.platform === 'win32' ? this.resourcePath.replace(/\//g, '\\\\') : this.resourcePath}';
import Component from '${formatPath(this.resourcePath)}';
import DriverUniversal from 'driver-universal';
var isSSR = window.__INITIAL_DATA__ && window.__INITIAL_DATA__.__SSR_ENABLED__;
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"files": [],
"references": [
{ "path": "packages/build-app-helpers" },
{ "path": "packages/plugin-app-core" },
{ "path": "packages/plugin-router" },
{ "path": "packages/plugin-helpers" },
Expand Down Expand Up @@ -32,7 +33,6 @@
{ "path": "packages/plugin-webpack5" },
{ "path": "packages/webpack-dev-mock" },
{ "path": "packages/plugin-ssr" },
{ "path": "packages/build-mpa-config" },
{ "path": "packages/build-app-helpers" }
{ "path": "packages/build-mpa-config" }
]
}
11 changes: 0 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4979,17 +4979,6 @@ build-plugin-app-core@0.1.20:
react-app-renderer "^0.1.9"
universal-env "^3.0.0"

build-plugin-rax-weex@1.0.4-0:
version "1.0.4-0"
resolved "https://registry.npm.taobao.org/build-plugin-rax-weex/download/build-plugin-rax-weex-1.0.4-0.tgz#519d107b2f1295497e469692cad8db17fc0a9480"
integrity sha1-UZ0Qey8SlUl+RpaSytjbF/wKlIA=
dependencies:
build-app-helpers "1.0.0-1"
build-mpa-config "1.0.2-0"
fs-extra "^9.0.1"
rax-compile-config "^0.2.16"
webpack-sources "^2.0.0"

builtin-status-codes@^3.0.0:
version "3.0.0"
resolved "https://registry.npm.taobao.org/builtin-status-codes/download/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8"
Expand Down

0 comments on commit 8d640ab

Please sign in to comment.