diff --git a/packages/plugin-core/src/index.ts b/packages/plugin-core/src/index.ts index 8984fc2f5..1ca6dc84d 100644 --- a/packages/plugin-core/src/index.ts +++ b/packages/plugin-core/src/index.ts @@ -5,6 +5,7 @@ import * as globby from 'globby' import Generator from './generator' import PageGenerator from './generator/pageGenerator' import getPages from './utils/getPages' +import formatWinPath from './utils/formatWinPath' export default (api) => { const { onHook, onGetWebpackConfig, registerMethod, context, getAllPlugin, setValue, modifyUserConfig } = api @@ -23,7 +24,7 @@ export default (api) => { // get runtime module const runtimeModules = plugins.map(({ pluginPath }) => { const modulePath = path.join(path.dirname(pluginPath), 'module.js'); - return fse.existsSync(modulePath) ? modulePath.split(path.sep).join('/') : false; + return fse.existsSync(modulePath) ? formatWinPath(modulePath) : false; }).filter(Boolean); // modify entry to src/app @@ -56,7 +57,7 @@ export default (api) => { const excludes = runtimeModules.map(modulePath => { // add default node_modules if (modulePath.includes('node_modules')) { - return process.platform === 'win32' ? modulePath.split(path.sep).join('/') : modulePath; + return process.platform === 'win32' ? formatWinPath(modulePath) : modulePath; } return false; @@ -99,6 +100,7 @@ export default (api) => { // register utils method registerMethod('getPages', getPages); + registerMethod('formatWinPath', formatWinPath); // registerMethod for modify page registerMethod('addPageExport', pageGenerator.addPageExport); diff --git a/packages/plugin-core/src/utils/formatWinPath.ts b/packages/plugin-core/src/utils/formatWinPath.ts new file mode 100644 index 000000000..a6983be6c --- /dev/null +++ b/packages/plugin-core/src/utils/formatWinPath.ts @@ -0,0 +1,7 @@ +import * as path from 'path' + +function formatWinPath(pathStr: string): string { + return pathStr.split(path.sep).join('/') +} + +export default formatWinPath diff --git a/packages/plugin-store/src/generator.ts b/packages/plugin-store/src/generator.ts index fa1ea72ac..acf66d209 100644 --- a/packages/plugin-store/src/generator.ts +++ b/packages/plugin-store/src/generator.ts @@ -42,7 +42,7 @@ export default class Generator { if (fse.pathExistsSync(pageModelsDir)) { const pageModels = recursiveReaddir(pageModelsDir).map(item => path.parse(item)) - pageModelsDir = pageModelsDir.split(path.sep).join('/') + pageModelsDir = this.applyMethod('formatWinPath', pageModelsDir) let importStr = '' let modelsStr = '' @@ -75,7 +75,7 @@ export default class Generator { let models = [] if (fse.pathExistsSync(appModelsDir)) { - appModelsDir = appModelsDir.split(path.sep).join('/') + appModelsDir = this.applyMethod('formatWinPath', appModelsDir) models = fse.readdirSync(appModelsDir).map(item => path.parse(item).name) }