From 54f7cffb768528aaef92cf591bc34879fcb9ab5b Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 20 Nov 2019 14:21:36 +0800 Subject: [PATCH] feat(app-plus-nvue): add disableScroll #209 --- .../webpack-uni-nvue-loader/lib/template.js | 66 ++++++++++++++++++- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/packages/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/template.js b/packages/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/template.js index 80b6ce559..27a344cf8 100644 --- a/packages/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/template.js +++ b/packages/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/template.js @@ -1,7 +1,67 @@ +const path = require('path') + +const { + removeExt, + normalizePath, + getPagesJson +} = require('@dcloudio/uni-cli-shared') + +const { + normalizeNodeModules +} = require('@dcloudio/webpack-uni-mp-loader/lib/shared') + +const SCROLLER_COMPONENTS = [ + 'list', + 'scroller', + 'scroll-view', + 'waterfall' +] + module.exports = function(content) { this.cacheable && this.cacheable() - if (content.indexOf('recycle-list') === -1) { - return `${content}` + const source = content.trim() + + if (SCROLLER_COMPONENTS.find(name => source.indexOf('<' + name) === 0)) { + return content } - return content + if (source.indexOf(' + resourcePath = normalizeNodeModules( + removeExt(normalizePath(path.relative(process.env.UNI_INPUT_DIR, this._module.issuer.issuer.resource))) + ) + } + + if (!process.UNI_NVUE_ENTRY[resourcePath]) { + return content + } + // 暂时实时读取配置信息,查找是否 disableScroll + const appJson = getPagesJson() + if (!appJson.nvue || !appJson.nvue.pages) { + return content + } + const pagePath = resourcePath + '.html' + const pageJson = appJson.nvue.pages.find(page => page.path === pagePath) + if (!pageJson) { + return content + } + Object.assign(appJson.globalStyle, appJson.globalStyle['app-plus'] || {}) + Object.assign(pageJson.style, pageJson.style['app-plus'] || {}) + const pageJsonStyle = Object.assign(appJson.globalStyle, pageJson.style) + if (pageJsonStyle.disableScroll === true) { + return content + } + + return `${content}` } -- GitLab