Merge branch '2.x' into dev

This commit is contained in:
chenjiahan 2020-11-15 15:38:22 +08:00
commit 71def44061
5 changed files with 44 additions and 51 deletions

View File

@ -1,5 +1,11 @@
# 更新日志 # 更新日志
## v2.6.2
`2020-11-15`
- 支持自定义 postcss 配置时传入数组格式的 plugins
### v2.6.1 ### v2.6.1
`2020-10-09` `2020-10-09`

View File

@ -7,12 +7,7 @@ import {
outputFileSync, outputFileSync,
} from 'fs-extra'; } from 'fs-extra';
import { merge } from 'webpack-merge'; import { merge } from 'webpack-merge';
import { import { SRC_DIR, getVantConfig, ROOT_WEBPACK_CONFIG_FILE } from './constant';
SRC_DIR,
getVantConfig,
ROOT_WEBPACK_CONFIG_FILE,
ROOT_POSTCSS_CONFIG_FILE,
} from './constant';
import { WebpackConfig } from './types'; import { WebpackConfig } from './types';
export const EXT_REGEXP = /\.\w+$/; export const EXT_REGEXP = /\.\w+$/;
@ -118,14 +113,6 @@ export function getWebpackConfig(defaultConfig: WebpackConfig): WebpackConfig {
return defaultConfig; 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 ModuleEnv = 'esmodule' | 'commonjs';
export type NodeEnv = 'production' | 'development' | 'test'; export type NodeEnv = 'production' | 'development' | 'test';
export type BuildTarget = 'site' | 'package'; export type BuildTarget = 'site' | 'package';

View File

@ -1,26 +1,36 @@
import { getPostcssConfig } from '../common'; import { existsSync } from 'fs-extra';
import { ROOT_POSTCSS_CONFIG_FILE } from '../common/constant';
type PostcssConfig = object & { type PostcssConfig = {
plugins?: object; plugins?: Record<string, unknown> | unknown[];
}; };
function mergePostcssConfig(config1: PostcssConfig, config2: PostcssConfig) { export function getRootPostcssConfig(): PostcssConfig {
const plugins = { if (existsSync(ROOT_POSTCSS_CONFIG_FILE)) {
...config1.plugins, return require(ROOT_POSTCSS_CONFIG_FILE);
...config2.plugins, }
}; return { plugins: [] };
}
function getPostcssPlugins(rootConfig: PostcssConfig) {
const plugins = rootConfig.plugins || [];
if (Array.isArray(plugins)) {
return [require('autoprefixer'), ...plugins];
}
return { return {
...config1, autoprefixer: {},
...config2, ...plugins,
plugins,
}; };
} }
const DEFAULT_CONFIG = { function resolvePostcssConfig() {
plugins: { const rootConfig = getRootPostcssConfig();
autoprefixer: {}, return {
}, ...rootConfig,
}; plugins: getPostcssPlugins(rootConfig),
};
}
module.exports = mergePostcssConfig(DEFAULT_CONFIG, getPostcssConfig()); module.exports = resolvePostcssConfig();

View File

@ -6,32 +6,22 @@ const overflowScrollReg = /scroll|auto/i;
function isElement(node: Element) { function isElement(node: Element) {
const ELEMENT_NODE_TYPE = 1; 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 // https://github.com/youzan/vant/issues/3823
// http://stackoverflow.com/questions/17016740/onscroll-function-is-not-working-for-chrome
function getScrollParent(el: Element, root: ScrollElement = window) { function getScrollParent(el: Element, root: ScrollElement = window) {
let node = el; let node = el;
while (node && node !== root && isElement(node)) { while (node && node !== root && isElement(node)) {
const { overflowY } = window.getComputedStyle(node); const { overflowY } = window.getComputedStyle(node);
if (overflowScrollReg.test(overflowY)) { if (overflowScrollReg.test(overflowY)) {
if (node.tagName !== 'BODY') { return node;
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;
}
} }
node = node.parentNode as Element; node = node.parentNode as Element;
} }

View File

@ -136,7 +136,7 @@ export default createComponent({
currentPosition = Math.min(currentPosition, -minOffset.value); currentPosition = Math.min(currentPosition, -minOffset.value);
} }
let targetOffset = Math.round(offset - currentPosition); let targetOffset = offset - currentPosition;
if (!props.loop) { if (!props.loop) {
targetOffset = range(targetOffset, minOffset.value, 0); targetOffset = range(targetOffset, minOffset.value, 0);
} }
@ -242,8 +242,8 @@ export default createComponent({
state.rect = rect; state.rect = rect;
state.swiping = true; state.swiping = true;
state.active = active; state.active = active;
state.width = Math.floor(+props.width || rect.width); state.width = +props.width || rect.width;
state.height = Math.floor(+props.height || rect.height); state.height = +props.height || rect.height;
state.offset = getTargetOffset(active); state.offset = getTargetOffset(active);
children.forEach((swipe) => { children.forEach((swipe) => {
swipe.setOffset(0); swipe.setOffset(0);