Skip to content

Commit 2a20912

Browse files
committed
feat: Update Ant Design Countdown usage and configure webpack for production caching, module resolution, and path aliases.
1 parent f5cf9fd commit 2a20912

7 files changed

Lines changed: 173 additions & 56 deletions

File tree

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
"version": "1.1.0",
44
"description": "webpack5 react 模板",
55
"main": "index.js",
6+
"sideEffects": [
7+
"*.css",
8+
"*.less",
9+
"*.scss",
10+
"*.sass",
11+
"*.styl"
12+
],
613
"scripts": {
714
"dev": "webpack serve --config webpack.dev.js --hot",
815
"build": "webpack --config webpack.prod.js"
@@ -27,6 +34,7 @@
2734
},
2835
"devDependencies": {
2936
"@eslint/js": "^9.16.0",
37+
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.2",
3038
"@swc/core": "^1.9.2",
3139
"@types/lodash-es": "^4.17.12",
3240
"@types/node": "^25.0.3",
@@ -52,6 +60,7 @@
5260
"postcss-normalize": "^13.0.1",
5361
"postcss-preset-env": "^10.1.1",
5462
"react-compiler-webpack": "^1.0.0",
63+
"react-refresh": "^0.18.0",
5564
"resolve-url-loader": "^5.0.0",
5665
"sass": "^1.81.0",
5766
"sass-loader": "^16.0.3",
@@ -74,4 +83,4 @@
7483
"engines": {
7584
"pnpm": "^10.0.0"
7685
}
77-
}
86+
}

pnpm-lock.yaml

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.tsx

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
1-
import React from 'react'
2-
import { Statistic, Row, Col } from 'antd'
3-
import { set } from 'lodash-es'
4-
import dayjs from 'dayjs'
5-
import './App.less';
6-
7-
const { Countdown } = Statistic;
1+
import React from "react";
2+
import { Statistic, Row, Col } from "antd";
3+
import { set } from "lodash-es";
4+
import dayjs from "dayjs";
5+
import "./App.less";
86

97
const App = () => {
108
const deadline = dayjs().unix() * 1000 + 1000 * 60 * 60 * 24 * 2 + 1000 * 30;
119
const onFinish = () => {
12-
const a = {}
13-
set(a, 'finish', true)
14-
}
10+
const a = {};
11+
set(a, "finish", true);
12+
};
1513

1614
return (
1715
<div className="container">
1816
<Row gutter={16} className="time">
1917
<Col span={12}>
20-
<Countdown title="Countdown" value={deadline} onFinish={onFinish} />
18+
<Statistic.Timer
19+
type="countdown"
20+
title="Countdown"
21+
value={deadline}
22+
onFinish={onFinish}
23+
/>
2124
</Col>
2225
<Col span={12}>
23-
<Countdown title="Million Seconds" value={deadline} format="HH:mm:ss:SSS"/>
26+
<Statistic.Timer
27+
type="countdown"
28+
title="Million Seconds"
29+
value={deadline}
30+
format="HH:mm:ss:SSS"
31+
/>
2432
</Col>
2533
<Col span={24} style={{ marginTop: 32 }}>
26-
<Countdown title="Day Level" value={deadline} format="D 天 H 时 m 分 s 秒" />
34+
<Statistic.Timer
35+
type="countdown"
36+
title="Day Level"
37+
value={deadline}
38+
format="D 天 H 时 m 分 s 秒"
39+
/>
2740
</Col>
2841
</Row>
2942
</div>
30-
)
31-
}
43+
);
44+
};
3245

33-
export default App
46+
export default App;

tsconfig.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1212

1313
/* Language and Environment */
14-
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
14+
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16-
"jsx": "preserve", /* Specify what JSX code is generated. */
16+
"jsx": "preserve" /* Specify what JSX code is generated. */,
1717
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1818
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1919
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
@@ -25,11 +25,13 @@
2525
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
2626

2727
/* Modules */
28-
"module": "commonjs", /* Specify what module code is generated. */
28+
"module": "esnext" /* Specify what module code is generated. */,
2929
// "rootDir": "./", /* Specify the root folder within your source files. */
30-
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
31-
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32-
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
30+
"moduleResolution": "bundler" /* Specify how TypeScript looks up a file from a given module specifier. */,
31+
"baseUrl": "./" /* Specify the base directory to resolve non-relative module names. */,
32+
"paths": {
33+
"@/*": ["src/*"]
34+
} /* Specify a set of entries that re-map imports to additional lookup locations. */,
3335
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
3436
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
3537
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
@@ -77,12 +79,12 @@
7779
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
7880
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
7981
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
80-
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
82+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
8183
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
82-
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
84+
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
8385

8486
/* Type Checking */
85-
"strict": true, /* Enable all strict type-checking options. */
87+
"strict": true /* Enable all strict type-checking options. */,
8688
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
8789
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
8890
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
@@ -104,6 +106,6 @@
104106

105107
/* Completeness */
106108
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
109+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
108110
}
109111
}

webpack.common.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ module.exports = () => {
4242
],
4343
resolve: {
4444
extensions: [".tsx", ".jsx", ".ts", ".js", ".json", ".wasm"],
45+
alias: {
46+
"@": path.resolve(__dirname, "src"),
47+
},
4548
},
4649
module: {
4750
rules: [

webpack.dev.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
const { merge } = require('webpack-merge');
2-
const common = require('./webpack.common.js');
1+
const { merge } = require("webpack-merge");
2+
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
3+
const common = require("./webpack.common.js");
34

4-
module.exports = env => {
5+
module.exports = (env) => {
56
return merge(common(env), {
6-
mode: 'development',
7+
mode: "development",
78
cache: {
8-
type: 'filesystem',
9+
type: "filesystem",
910
// 可选配置
1011
buildDependencies: {
11-
config: [__filename], // 当构建依赖的config文件(通过 require 依赖)内容发生变化时,缓存失效
12+
config: [__filename], // 当构建依赖的config文件(通过 require 依赖)内容发生变化时,缓存失效
1213
},
13-
name: 'development-cache', // 配置以name为隔离,创建不同的缓存文件,如生成PC或mobile不同的配置缓存
14+
name: "development-cache", // 配置以name为隔离,创建不同的缓存文件,如生成PC或mobile不同的配置缓存
1415
},
1516
devServer: {
1617
port: 8081,
17-
host: '0.0.0.0',
18-
allowedHosts: 'all'
18+
host: "0.0.0.0",
19+
allowedHosts: "all",
1920
},
21+
plugins: [new ReactRefreshWebpackPlugin()],
2022
optimization: {
2123
moduleIds: "deterministic",
2224
},
2325
});
24-
}
26+
};

0 commit comments

Comments
 (0)