Skip to content

Commit e3b1d85

Browse files
committed
chore: 替换 moment 为 dayjs
1 parent 142a4ea commit e3b1d85

File tree

7 files changed

+31
-8
lines changed

7 files changed

+31
-8
lines changed

config/webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const typescriptFormatter = require('react-dev-utils/typescriptFormatter')
2727
const CompressionPlugin = require('compression-webpack-plugin')
2828

2929
// ==== plugins
30+
const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin')
3031
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
3132
const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin')
3233
const os = require('os')
@@ -613,6 +614,9 @@ module.exports = function(webpackEnv) {
613614
formatter: isEnvProduction ? typescriptFormatter : undefined
614615
}),
615616
isEnvProduction && new CompressionPlugin(),
617+
new AntdDayjsWebpackPlugin({
618+
preset: 'antdv3'
619+
}),
616620
new HappyPack({
617621
id: 'babelInside',
618622
threadPool: happyThreadPool, // 指定进程池

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"camelcase": "^5.2.0",
1818
"case-sensitive-paths-webpack-plugin": "2.2.0",
1919
"css-loader": "2.1.1",
20+
"dayjs": "^1.8.31",
2021
"dotenv": "6.2.0",
2122
"dotenv-expand": "4.2.0",
2223
"eslint": "^6.1.0",
@@ -142,6 +143,7 @@
142143
},
143144
"devDependencies": {
144145
"add-asset-html-webpack-plugin": "^3.1.3",
146+
"antd-dayjs-webpack-plugin": "^1.0.0",
145147
"babel-plugin-import": "^1.12.1",
146148
"compression-webpack-plugin": "^3.0.0",
147149
"git-cz": "^3.3.0",

src/components/Discuss/list.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React, { useState, useEffect } from 'react'
22
import { useSelector } from 'react-redux'
3-
import PropTypes from 'prop-types'
43

54
import axios from '@/utils/axios'
65
import { translateMarkdown } from '@/utils'
7-
import moment from 'moment'
6+
import dayjs from '@/utils/dayjs'
87
import AppAvatar from '@/components/Avatar'
98
import { Comment, Button, Tooltip, Input, Icon, Popconfirm, message } from 'antd'
109

@@ -85,7 +84,7 @@ function CommentItem(props) {
8584
}
8685
datetime={
8786
<Tooltip title={item.createdAt}>
88-
<span>{moment(item.createdAt).fromNow()}</span>
87+
<span>{dayjs(item.createdAt).fromNow()}</span>
8988
</Tooltip>
9089
}>
9190
{replyVisible && (

src/utils/dayjs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import dayjs from 'dayjs'
2+
import relativeTime from 'dayjs/plugin/relativeTime'
3+
4+
dayjs.extend(relativeTime)
5+
6+
export default dayjs

src/views/admin/article/manager/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Table, Form, Tag, Switch, message, Input, Button, Popconfirm, Select }
55
import axios from '@/utils/axios'
66

77
import { Link } from 'react-router-dom'
8-
import moment from 'moment'
8+
import dayjs from '@/utils/dayjs'
99
import download from '@/utils/download'
1010

1111
import useAntdTable from '@/hooks/useAntdTable'
@@ -62,12 +62,12 @@ function ArticleManager(props) {
6262
{
6363
title: '发布时间',
6464
dataIndex: 'createdAt',
65-
sorter: (a, b) => (moment(a.createdAt).isBefore(b.createdAt) ? 1 : -1)
65+
sorter: (a, b) => (dayjs(a.createdAt).isBefore(b.createdAt) ? 1 : -1)
6666
},
6767
{
6868
title: '修改时间',
6969
dataIndex: 'updatedAt',
70-
sorter: (a, b) => (moment(a.updatedAt).isBefore(b.updatedAt) ? 1 : -1)
70+
sorter: (a, b) => (dayjs(a.updatedAt).isBefore(b.updatedAt) ? 1 : -1)
7171
},
7272
{
7373
dataIndex: 'id',

src/views/admin/user/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState } from 'react'
22
import { Table, Input, Tag, Form, Switch, Button, Popconfirm, Select, DatePicker } from 'antd'
33

44
import axios from '@/utils/axios'
5-
import moment from 'moment'
5+
import dayjs from '@/utils/dayjs'
66

77
import useAntdTable from '@/hooks/useAntdTable'
88
import useBreadcrumb from '@/hooks/useBreadcrumb'
@@ -52,7 +52,7 @@ function AdminUser(props) {
5252
{
5353
title: '注册时间',
5454
dataIndex: 'createdAt',
55-
sorter: (a, b) => (moment(a.createdAt).isBefore(b.createdAt) ? 1 : -1)
55+
sorter: (a, b) => (dayjs(a.createdAt).isBefore(b.createdAt) ? 1 : -1)
5656
},
5757
{
5858
dataIndex: 'id',

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,13 @@ ansi-styles@^3.2.0, ansi-styles@^3.2.1:
17641764
dependencies:
17651765
color-convert "^1.9.0"
17661766

1767+
antd-dayjs-webpack-plugin@^1.0.0:
1768+
version "1.0.0"
1769+
resolved "https://registry.npm.taobao.org/antd-dayjs-webpack-plugin/download/antd-dayjs-webpack-plugin-1.0.0.tgz#e3f4b0bce3985aa0d75a36341b3f9f67b486423a"
1770+
integrity sha1-4/SwvOOYWqDXWjY0Gz+fZ7SGQjo=
1771+
dependencies:
1772+
dayjs "*"
1773+
17671774
antd@^3.26.6:
17681775
version "3.26.8"
17691776
resolved "https://registry.npm.taobao.org/antd/download/antd-3.26.8.tgz#e40982c5cdb6c5c2c5f037ead27889b5f71e4ea3"
@@ -3446,6 +3453,11 @@ data-urls@^1.0.0, data-urls@^1.1.0:
34463453
whatwg-mimetype "^2.2.0"
34473454
whatwg-url "^7.0.0"
34483455

3456+
dayjs@*, dayjs@^1.8.31:
3457+
version "1.8.31"
3458+
resolved "https://registry.npm.taobao.org/dayjs/download/dayjs-1.8.31.tgz#0cd1114c2539dd5ad9428be0c38df6d4bb40b9d3"
3459+
integrity sha1-DNERTCU53VrZQovgw4321LtAudM=
3460+
34493461
debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.9:
34503462
version "2.6.9"
34513463
resolved "https://registry.npm.taobao.org/debug/download/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"

0 commit comments

Comments
 (0)