diff --git a/packages/uni-cli-shared/lib/pages.js b/packages/uni-cli-shared/lib/pages.js index 2dfd2df33a1083945b331a4e579a1f55649bb1e2..daa4455ec83053fe71d471abc0df8b8b2b1746de 100644 --- a/packages/uni-cli-shared/lib/pages.js +++ b/packages/uni-cli-shared/lib/pages.js @@ -339,20 +339,27 @@ const isDirectory = source => fs.lstatSync(source).isDirectory() function getAutoComponentsByDir (componentsPath, absolute = false) { const components = {} try { - fs.existsSync(componentsPath) && fs.readdirSync(componentsPath).forEach(name => { - const folder = path.resolve(componentsPath, name) - if (!isDirectory(folder)) { - return + if (fs.existsSync(componentsPath)) { + let importComponentsDir = '@/components' + const uniModulesDir = path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules') + if (!absolute && componentsPath.includes(uniModulesDir)) { + importComponentsDir = `@/uni_modules/${path.basename(path.dirname(componentsPath))}/components` } - const importDir = absolute ? normalizePath(folder) : `@/components/${name}` - // 读取文件夹文件列表,比对文件名(fs.existsSync在大小写不敏感的系统会匹配不准确) - const files = fs.readdirSync(folder) - if (files.includes(name + '.vue')) { - components[`^${name}$`] = `${importDir}/${name}.vue` - } else if (files.includes(name + '.nvue')) { - components[`^${name}$`] = `${importDir}/${name}.nvue` - } - }) + fs.readdirSync(componentsPath).forEach(name => { + const folder = path.resolve(componentsPath, name) + if (!isDirectory(folder)) { + return + } + const importDir = absolute ? normalizePath(folder) : `${importComponentsDir}/${name}` + // 读取文件夹文件列表,比对文件名(fs.existsSync在大小写不敏感的系统会匹配不准确) + const files = fs.readdirSync(folder) + if (files.includes(name + '.vue')) { + components[`^${name}$`] = `${importDir}/${name}.vue` + } else if (files.includes(name + '.nvue')) { + components[`^${name}$`] = `${importDir}/${name}.nvue` + } + }) + } } catch (e) { console.log(e) } @@ -365,8 +372,9 @@ function initAutoComponents () { global.uniModules.forEach(module => { componentsDirs.push(path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', module, 'components')) }) - componentsDirs.forEach(componentsDir => { - const currentComponents = getAutoComponentsByDir(componentsDir, true) + componentsDirs.forEach((componentsDir) => { + // 根目录 components 使用相对路径,uni_modules 使用绝对路径 + const currentComponents = getAutoComponentsByDir(componentsDir, false) Object.keys(currentComponents).forEach(name => { (allComponents[name] || (allComponents[name] = [])).push(currentComponents[name]) }) @@ -384,7 +392,6 @@ function initAutoComponents () { conflictFiles.forEach(files => { let usedFile console.warn('easycom组件冲突:[' + files.map((file, index) => { - file = path.relative(process.env.UNI_INPUT_DIR, file) if (index === 0) { usedFile = file } diff --git a/packages/webpack-uni-pages-loader/lib/platforms/mp.js b/packages/webpack-uni-pages-loader/lib/platforms/mp.js index 0ee26bc9fdf3c8c759179cbe18656063fe49b7c3..ebb59dfcf942c068153d2b6b3db082290b6cff83 100644 --- a/packages/webpack-uni-pages-loader/lib/platforms/mp.js +++ b/packages/webpack-uni-pages-loader/lib/platforms/mp.js @@ -171,6 +171,12 @@ function getCondition (pagesJson) { } return false } + +function trimAppJson (app) { + delete app.topWindow + delete app.leftWindow + delete app.rightWindow +} module.exports = function (pagesJson, manifestJson, project = {}) { const app = { @@ -245,14 +251,14 @@ module.exports = function (pagesJson, manifestJson, project = {}) { return { app: { name: 'app', - content: app + content: trimAppJson(app) } } } return { app: { name: 'app', - content: app + content: trimAppJson(app) }, project: { name: 'project.config', @@ -311,7 +317,7 @@ module.exports = function (pagesJson, manifestJson, project = {}) { return { app: { name: 'app', - content: app + content: trimAppJson(app) }, project: { name: 'project.config',