diff --git a/packages/vant-cli/changelog.md b/packages/vant-cli/changelog.md index 50728632b..15a57fc4e 100644 --- a/packages/vant-cli/changelog.md +++ b/packages/vant-cli/changelog.md @@ -1,5 +1,11 @@ # 更新日志 +## v2.6.2 + +`2020-11-15` + +- 支持自定义 postcss 配置时传入数组格式的 plugins + ### v2.6.1 `2020-10-09` diff --git a/packages/vant-cli/src/common/index.ts b/packages/vant-cli/src/common/index.ts index a723f7f93..0feb4efaa 100644 --- a/packages/vant-cli/src/common/index.ts +++ b/packages/vant-cli/src/common/index.ts @@ -7,12 +7,7 @@ import { outputFileSync, } from 'fs-extra'; import { merge } from 'webpack-merge'; -import { - SRC_DIR, - getVantConfig, - ROOT_WEBPACK_CONFIG_FILE, - ROOT_POSTCSS_CONFIG_FILE, -} from './constant'; +import { SRC_DIR, getVantConfig, ROOT_WEBPACK_CONFIG_FILE } from './constant'; import { WebpackConfig } from './types'; export const EXT_REGEXP = /\.\w+$/; @@ -118,14 +113,6 @@ export function getWebpackConfig(defaultConfig: WebpackConfig): WebpackConfig { return defaultConfig; } -export function getPostcssConfig() { - if (existsSync(ROOT_POSTCSS_CONFIG_FILE)) { - return require(ROOT_POSTCSS_CONFIG_FILE); - } - - return {}; -} - export type ModuleEnv = 'esmodule' | 'commonjs'; export type NodeEnv = 'production' | 'development' | 'test'; export type BuildTarget = 'site' | 'package'; diff --git a/packages/vant-cli/src/config/postcss.config.ts b/packages/vant-cli/src/config/postcss.config.ts index 51fbb6c5e..e171a429d 100644 --- a/packages/vant-cli/src/config/postcss.config.ts +++ b/packages/vant-cli/src/config/postcss.config.ts @@ -1,26 +1,36 @@ -import { getPostcssConfig } from '../common'; +import { existsSync } from 'fs-extra'; +import { ROOT_POSTCSS_CONFIG_FILE } from '../common/constant'; -type PostcssConfig = object & { - plugins?: object; +type PostcssConfig = { + plugins?: Record | unknown[]; }; -function mergePostcssConfig(config1: PostcssConfig, config2: PostcssConfig) { - const plugins = { - ...config1.plugins, - ...config2.plugins, - }; +export function getRootPostcssConfig(): PostcssConfig { + if (existsSync(ROOT_POSTCSS_CONFIG_FILE)) { + return require(ROOT_POSTCSS_CONFIG_FILE); + } + return { plugins: [] }; +} + +function getPostcssPlugins(rootConfig: PostcssConfig) { + const plugins = rootConfig.plugins || []; + + if (Array.isArray(plugins)) { + return [require('autoprefixer'), ...plugins]; + } return { - ...config1, - ...config2, - plugins, + autoprefixer: {}, + ...plugins, }; } -const DEFAULT_CONFIG = { - plugins: { - autoprefixer: {}, - }, -}; +function resolvePostcssConfig() { + const rootConfig = getRootPostcssConfig(); + return { + ...rootConfig, + plugins: getPostcssPlugins(rootConfig), + }; +} -module.exports = mergePostcssConfig(DEFAULT_CONFIG, getPostcssConfig()); +module.exports = resolvePostcssConfig(); diff --git a/packages/vant-use/src/useScrollParent/index.ts b/packages/vant-use/src/useScrollParent/index.ts index 1c546402b..0b5b81ef8 100644 --- a/packages/vant-use/src/useScrollParent/index.ts +++ b/packages/vant-use/src/useScrollParent/index.ts @@ -6,32 +6,22 @@ const overflowScrollReg = /scroll|auto/i; function isElement(node: Element) { const ELEMENT_NODE_TYPE = 1; - return node.tagName !== 'HTML' && node.nodeType === ELEMENT_NODE_TYPE; + return ( + node.tagName !== 'HTML' && + node.tagName !== 'BODY' && + node.nodeType === ELEMENT_NODE_TYPE + ); } -// http://w3help.org/zh-cn/causes/SD9013 -// http://stackoverflow.com/questions/17016740/onscroll-function-is-not-working-for-chrome +// https://github.com/youzan/vant/issues/3823 function getScrollParent(el: Element, root: ScrollElement = window) { let node = el; while (node && node !== root && isElement(node)) { const { overflowY } = window.getComputedStyle(node); - if (overflowScrollReg.test(overflowY)) { - if (node.tagName !== 'BODY') { - return node; - } - - // see: https://github.com/youzan/vant/issues/3823 - const { overflowY: htmlOverflowY } = window.getComputedStyle( - node.parentNode as Element - ); - - if (overflowScrollReg.test(htmlOverflowY)) { - return node; - } + return node; } - node = node.parentNode as Element; } diff --git a/src/swipe/index.js b/src/swipe/index.js index 8b27be050..ee58bfbdc 100644 --- a/src/swipe/index.js +++ b/src/swipe/index.js @@ -136,7 +136,7 @@ export default createComponent({ currentPosition = Math.min(currentPosition, -minOffset.value); } - let targetOffset = Math.round(offset - currentPosition); + let targetOffset = offset - currentPosition; if (!props.loop) { targetOffset = range(targetOffset, minOffset.value, 0); } @@ -242,8 +242,8 @@ export default createComponent({ state.rect = rect; state.swiping = true; state.active = active; - state.width = Math.floor(+props.width || rect.width); - state.height = Math.floor(+props.height || rect.height); + state.width = +props.width || rect.width; + state.height = +props.height || rect.height; state.offset = getTargetOffset(active); children.forEach((swipe) => { swipe.setOffset(0);