From c3dbde6a69411db0dff8e17b8c92447fe4b73abc Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 18 Mar 2020 20:48:00 +0800 Subject: [PATCH] fix(cli): compatible with windows (normalize path) --- packages/uni-cli-shared/lib/url-loader.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/uni-cli-shared/lib/url-loader.js b/packages/uni-cli-shared/lib/url-loader.js index e274352a4..e4ce16a7d 100644 --- a/packages/uni-cli-shared/lib/url-loader.js +++ b/packages/uni-cli-shared/lib/url-loader.js @@ -1,5 +1,9 @@ const path = require('path') +const isWin = /^win/.test(process.platform) + +const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path) + const defaultOptions = { limit: -1, fallback: { @@ -10,12 +14,12 @@ const defaultOptions = { process.env.UNI_PLATFORM === 'app-plus' && process.env.UNI_USING_V3 ) { // app-plus v3 下路径不能以/开头 - return path.relative(process.env.UNI_INPUT_DIR, resourcePath) + return normalizePath(path.relative(process.env.UNI_INPUT_DIR, resourcePath)) } - return '/' + path.relative(process.env.UNI_INPUT_DIR, resourcePath) + return '/' + normalizePath(path.relative(process.env.UNI_INPUT_DIR, resourcePath)) }, outputPath (url, resourcePath, context) { - return path.relative(process.env.UNI_INPUT_DIR, resourcePath) + return normalizePath(path.relative(process.env.UNI_INPUT_DIR, resourcePath)) } } } -- GitLab