diff --git a/antd-tools/getWebpackConfig.js b/antd-tools/getWebpackConfig.js index 8b4deef31..c483603a3 100644 --- a/antd-tools/getWebpackConfig.js +++ b/antd-tools/getWebpackConfig.js @@ -80,7 +80,6 @@ function getWebpackConfig(modules) { }, module: { - noParse: [/moment.js/], rules: [ { test: /\.vue$/, diff --git a/components/_util/interopDefault.js b/components/_util/interopDefault.js deleted file mode 100644 index d1adc3c40..000000000 --- a/components/_util/interopDefault.js +++ /dev/null @@ -1,4 +0,0 @@ -// https://github.com/moment/moment/issues/3650 -export default function interopDefault(m) { - return m.default || m; -} diff --git a/components/_util/moment-util.js b/components/_util/moment-util.js deleted file mode 100644 index 002820474..000000000 --- a/components/_util/moment-util.js +++ /dev/null @@ -1,75 +0,0 @@ -import interopDefault from './interopDefault'; -import moment from 'moment'; -import warning from './warning'; -import isNil from 'lodash-es/isNil'; - -export const TimeType = { - validator(value) { - return typeof value === 'string' || isNil(value) || moment.isMoment(value); - }, -}; - -export const TimesType = { - validator(value) { - if (Array.isArray(value)) { - return ( - value.length === 0 || - value.findIndex(val => typeof val !== 'string') === -1 || - value.findIndex(val => !isNil(val) && !moment.isMoment(val)) === -1 - ); - } - return false; - }, -}; - -export const TimeOrTimesType = { - validator(value) { - if (Array.isArray(value)) { - return ( - value.length === 0 || - value.findIndex(val => typeof val !== 'string') === -1 || - value.findIndex(val => !isNil(val) && !moment.isMoment(val)) === -1 - ); - } else { - return typeof value === 'string' || isNil(value) || moment.isMoment(value); - } - }, -}; - -export function checkValidate(componentName, value, propName, valueFormat) { - const values = Array.isArray(value) ? value : [value]; - values.forEach(val => { - if (!val) return; - valueFormat && - warning( - interopDefault(moment)(val, valueFormat).isValid(), - componentName, - `When set \`valueFormat\`, \`${propName}\` should provides invalidate string time. `, - ); - !valueFormat && - warning( - interopDefault(moment).isMoment(val) && val.isValid(), - componentName, - `\`${propName}\` provides invalidate moment time. If you want to set empty value, use \`null\` instead.`, - ); - }); -} -export const stringToMoment = (value, valueFormat) => { - if (Array.isArray(value)) { - return value.map(val => - typeof val === 'string' && val ? interopDefault(moment)(val, valueFormat) : val || null, - ); - } else { - return typeof value === 'string' && value - ? interopDefault(moment)(value, valueFormat) - : value || null; - } -}; - -export const momentToString = (value, valueFormat) => { - if (Array.isArray(value)) { - return value.map(val => (interopDefault(moment).isMoment(val) ? val.format(valueFormat) : val)); - } else { - return interopDefault(moment).isMoment(value) ? value.format(valueFormat) : value; - } -}; diff --git a/tests/shared/demoTest.js b/tests/shared/demoTest.js index 3870187f6..d106b629c 100644 --- a/tests/shared/demoTest.js +++ b/tests/shared/demoTest.js @@ -1,7 +1,7 @@ import glob from 'glob'; import { mount } from '@vue/test-utils'; import MockDate from 'mockdate'; -import moment from 'moment'; +import dayjs from 'dayjs'; import antd from 'ant-design-vue'; import { sleep } from '../utils'; @@ -15,7 +15,7 @@ export default function demoTest(component, options = {}) { testMethod = test.skip; } testMethod(`renders ${file} correctly`, async () => { - MockDate.set(moment('2016-11-22')); + MockDate.set(dayjs('2016-11-22')); const demo = require(`../.${file}`).default || require(`../.${file}`); document.body.innerHTML = ''; const wrapper = mount(demo, { global: { plugins: [antd] }, attachTo: document.body }); diff --git a/tests/utils.js b/tests/utils.js index ce873c5b5..64a875e31 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -1,9 +1,9 @@ -import moment from 'moment'; +import dayjs from 'dayjs'; import MockDate from 'mockdate'; import { nextTick } from 'vue'; export function setMockDate(dateString = '2017-09-18T03:30:07.795') { - MockDate.set(moment(dateString)); + MockDate.set(dayjs(dateString)); } export function resetMockDate() { diff --git a/webpack.build.conf.js b/webpack.build.conf.js index 1da4ffd91..5d7078cad 100644 --- a/webpack.build.conf.js +++ b/webpack.build.conf.js @@ -2,14 +2,6 @@ const getWebpackConfig = require('./antd-tools/getWebpackConfig'); const IgnoreEmitPlugin = require('ignore-emit-webpack-plugin'); const darkVars = require('./scripts/dark-vars'); -const { webpack } = getWebpackConfig; -// noParse still leave `require('./locale' + name)` in dist files -// ignore is better -// http://stackoverflow.com/q/25384360 -function ignoreMomentLocale(webpackConfig) { - delete webpackConfig.module.noParse; - webpackConfig.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)); -} function addLocales(webpackConfig) { let packageName = 'antd-with-locales'; @@ -20,20 +12,19 @@ function addLocales(webpackConfig) { webpackConfig.output.filename = '[name].js'; } -function externalMoment(config) { - config.externals.moment = { - root: 'moment', - commonjs2: 'moment', - commonjs: 'moment', - amd: 'moment', +function externalDayjs(config) { + config.externals.dayjs = { + root: 'dayjs', + commonjs2: 'dayjs', + commonjs: 'dayjs', + amd: 'dayjs', }; } const webpackConfig = getWebpackConfig(false); if (process.env.RUN_ENV === 'PRODUCTION') { webpackConfig.forEach(config => { - ignoreMomentLocale(config); - externalMoment(config); + externalDayjs(config); addLocales(config); }); } @@ -41,8 +32,7 @@ if (process.env.RUN_ENV === 'PRODUCTION') { const webpackDarkConfig = getWebpackConfig(false); webpackDarkConfig.forEach(config => { - ignoreMomentLocale(config); - externalMoment(config); + externalDayjs(config); // rename default entry to ${theme} entry Object.keys(config.entry).forEach(entryName => {