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
`2020-10-09`

View File

@ -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';

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 & {
plugins?: object;
type PostcssConfig = {
plugins?: Record<string, unknown> | 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();

View File

@ -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;
}

View File

@ -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);