Skip to content

Commit 78d418e

Browse files
author
sunss
committed
chore(�): config balel and webpack
1 parent 3cd9f4f commit 78d418e

File tree

8 files changed

+79
-47
lines changed

8 files changed

+79
-47
lines changed

.eslintrc.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ module.exports = {
2121
parserOptions: {
2222
ecmaVersion: 6,
2323
sourceType: 'module',
24+
createDefaultProgram: true,
2425
ecmaFeatures: {
2526
jsx: true,
2627
},
27-
// project: './tsconfig.eslint.json',
28+
project: './tsconfig.eslint.json',
29+
// project: {},
2830
},
2931
rules: {
3032
'jsx-no-lambda': 0,
@@ -46,7 +48,7 @@ module.exports = {
4648
'no-submodule-imports': 0,
4749
'no-case-declarations': 1,
4850
'@typescript-eslint/no-empty-function': 0,
49-
'@typescript-eslint/ban-ts-ignore': 1,
51+
// '@typescript-eslint/ban-ts-ignore': 1,
5052
'@typescript-eslint/indent': 0,
5153
'jsx-alignment': 0,
5254
'jsx-wrap-multiline': 0,
@@ -107,8 +109,8 @@ module.exports = {
107109
'react/require-extension': 0,
108110
'react/self-closing-comp': 0,
109111
'react/sort-comp': 0,
110-
'redux-saga/no-yield-in-race': 2,
111-
'redux-saga/yield-effects': 2,
112+
// 'redux-saga/no-yield-in-race': 2,
113+
// 'redux-saga/yield-effects': 2,
112114
'require-yield': 0,
113115
},
114116
settings: {
@@ -117,7 +119,7 @@ module.exports = {
117119
},
118120
'import/resolver': {
119121
webpack: {
120-
config: './internals/webpack/webpack.prod.babel.js',
122+
config: './config/webpack.base.js',
121123
},
122124
typescript: {
123125
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`

babel.config.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const { argv } = require('yargs');
2+
const isDev = argv.mode === 'development';
3+
14
module.exports = {
25
presets: [
36
[
@@ -16,14 +19,27 @@ module.exports = {
1619
'@babel/preset-typescript',
1720
],
1821
plugins: [
19-
'react-hot-loader/babel',
22+
'lodash',
23+
'@babel/plugin-transform-runtime',
2024
// 'babel-plugin-styled-components',
25+
// '@babel/plugin-transform-react-inline-elements',
26+
// '@babel/plugin-transform-react-constant-elements',
2127
'@babel/plugin-proposal-class-properties',
2228
'@babel/plugin-syntax-dynamic-import',
23-
],
29+
'react-hot-loader/babel',
30+
isDev && [
31+
'import',
32+
{
33+
libraryName: 'antd',
34+
libraryDirectory: 'es',
35+
style: true, // or 'css'
36+
},
37+
'antd',
38+
],
39+
].filter(Boolean),
2440
env: {
2541
production: {
26-
only: ['app'],
42+
// only: ['app'],
2743
plugins: [
2844
'lodash',
2945
'transform-react-remove-prop-types',

config/webpack.base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
entry: './src/index.tsx',
99
output: {
1010
path: path.resolve(__dirname, '..dist'),
11-
// filename: '[name].[contenthash].js',
11+
filename: '[name].[contenthash].js',
1212
publicPath: '',
1313
},
1414
module: {

config/webpack.dev.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const devConfig = {
2929

3030
devServer: {
3131
port: 3000,
32-
contentBase: '../dist',
32+
// contentBase: '../dist',
33+
publicPath: '/',
3334
open: true,
3435
hot: true,
3536
historyApiFallback: true,

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"@typescript-eslint/parser": "^4.29.0",
6363
"babel-loader": "^8.2.2",
6464
"babel-plugin-dynamic-import-node": "^2.3.3",
65+
"babel-plugin-import": "^1.13.3",
6566
"babel-plugin-lodash": "^3.3.4",
6667
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
6768
"clean-webpack-plugin": "^4.0.0-alpha.0",
@@ -107,7 +108,8 @@
107108
"webpack-dev-middleware": "^5.0.0",
108109
"webpack-dev-server": "^3.11.2",
109110
"webpack-hot-middleware": "^2.25.0",
110-
"webpack-pwa-manifest": "^4.3.0"
111+
"webpack-pwa-manifest": "^4.3.0",
112+
"yargs": "^17.1.0"
111113
},
112114
"resolutions": {
113115
"babel-loader": "8.2.2"

src/App.tsx

+25-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { Helmet, HelmetProvider } from 'react-helmet-async';
3-
import { Switch, Route, Link } from 'react-router-dom';
3+
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom';
44
import { Button, Empty, Space } from 'antd';
55
import HomePage from './pages/Home';
66
import AboutPage from './pages/About';
@@ -10,31 +10,33 @@ import { hot } from 'react-hot-loader/root';
1010
function App() {
1111
return (
1212
<HelmetProvider>
13-
<div className="app">
14-
<Helmet titleTemplate="%s - webpack-react-typescript" defaultTitle="React App">
15-
<meta name="description" content="a webpack5.x + react + typescript practices" />
16-
</Helmet>
13+
<Router>
14+
<div className="app">
15+
<Helmet titleTemplate="%s - webpack-react-typescript" defaultTitle="React App">
16+
<meta name="description" content="a webpack5.x + react + typescript practices" />
17+
</Helmet>
1718

18-
<h1>欢迎使用 webpack-react-typescript 模板</h1>
19-
<Space align="center" size={60}>
20-
<Link to="/">
21-
<Button>HomePage</Button>
22-
</Link>
23-
<Link to="/about">
24-
<Button type="primary">AboutPage</Button>
25-
</Link>
26-
</Space>
19+
<h1>欢迎使用 webpack-react-typescript 模板</h1>
20+
<Space size={60}>
21+
<Link to="/">
22+
<Button>HomePage</Button>
23+
</Link>
24+
<Link to="/about">
25+
<Button type="primary">AboutPage</Button>
26+
</Link>
27+
</Space>
2728

28-
{/* Roues */}
29-
<Switch>
30-
<Route exact path="/" component={HomePage} />
31-
<Route path="/about" component={AboutPage} />
32-
<Route render={() => <Empty />} />
33-
</Switch>
29+
{/* Roues */}
30+
<Switch>
31+
<Route exact path="/" component={HomePage} />
32+
<Route path="/about" component={AboutPage} />
33+
<Route render={() => <Empty />} />
34+
</Switch>
3435

35-
<img src={logo} alt="" style={{ width: 400, height: 400 }} />
36-
<h4>a webpack5.x + react + typescript practices</h4>
37-
</div>
36+
<img src={logo} alt="" style={{ width: 400, height: 400 }} />
37+
<h4>a webpack5.x + react + typescript practices</h4>
38+
</div>
39+
</Router>
3840
</HelmetProvider>
3941
);
4042
}

src/index.tsx

+11-10
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import ReactDOM from 'react-dom';
33
import App from './App';
44
import './index.less';
55

6-
const MOUNT_NODE = document.getElementById('app') as HTMLElement;
6+
// const MOUNT_NODE = document.getElementById('app') as HTMLElement;
77

8-
if (module.hot) {
9-
// Hot reloadable translation json files
10-
// modules.hot.accept does not accept dynamic dependencies,
11-
// have to be constants at compile-time
12-
module.hot.accept([], () => {
13-
ReactDOM.unmountComponentAtNode(MOUNT_NODE);
14-
ReactDOM.render(<App />, document.getElementById('root'));
15-
});
16-
}
8+
ReactDOM.render(<App />, document.getElementById('root'));
9+
// if (module.hot) {
10+
// // Hot reloadable translation json files
11+
// // modules.hot.accept does not accept dynamic dependencies,
12+
// // have to be constants at compile-time
13+
// module.hot.accept([], () => {
14+
// ReactDOM.unmountComponentAtNode(MOUNT_NODE);
15+
// ReactDOM.render(<App />, document.getElementById('root'));
16+
// });
17+
// }

yarn.lock

+11-3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
dependencies:
206206
"@babel/types" "^7.15.0"
207207

208-
"@babel/helper-module-imports@^7.0.0-beta.49", "@babel/helper-module-imports@^7.12.13", "@babel/helper-module-imports@^7.14.5":
208+
"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.0.0-beta.49", "@babel/helper-module-imports@^7.12.13", "@babel/helper-module-imports@^7.14.5":
209209
version "7.14.5"
210210
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.14.5.tgz#6d1a44df6a38c957aa7c312da076429f11b422f3"
211211
integrity sha512-SwrNHu5QWS84XlHwGYPDtCxcA0hrSlL2yhWYLgeOc0w7ccOl2qv4s/nARI0aYZW+bSwAL5CukeXA47B/1NKcnQ==
@@ -1006,7 +1006,7 @@
10061006
core-js-pure "^3.16.0"
10071007
regenerator-runtime "^0.13.4"
10081008

1009-
"@babel/runtime@^7.1.2", "@babel/runtime@^7.10.1", "@babel/runtime@^7.10.2", "@babel/runtime@^7.10.4", "@babel/runtime@^7.11.1", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.5", "@babel/runtime@^7.6.3", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
1009+
"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.10.1", "@babel/runtime@^7.10.2", "@babel/runtime@^7.10.4", "@babel/runtime@^7.11.1", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.5", "@babel/runtime@^7.6.3", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
10101010
version "7.14.8"
10111011
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.14.8.tgz#7119a56f421018852694290b9f9148097391b446"
10121012
integrity sha512-twj3L8Og5SaCRCErB4x4ajbvBIVV77CGeFglHpeg5WC5FF8TZzBWXtTJ4MqaD9QszLYTtr+IsaAL2rEUevb+eg==
@@ -2444,6 +2444,14 @@ babel-plugin-dynamic-import-node@^2.3.3:
24442444
dependencies:
24452445
object.assign "^4.1.0"
24462446

2447+
babel-plugin-import@^1.13.3:
2448+
version "1.13.3"
2449+
resolved "https://registry.yarnpkg.com/babel-plugin-import/-/babel-plugin-import-1.13.3.tgz#9dbbba7d1ac72bd412917a830d445e00941d26d7"
2450+
integrity sha512-1qCWdljJOrDRH/ybaCZuDgySii4yYrtQ8OJQwrcDqdt0y67N30ng3X3nABg6j7gR7qUJgcMa9OMhc4AGViDwWw==
2451+
dependencies:
2452+
"@babel/helper-module-imports" "^7.0.0"
2453+
"@babel/runtime" "^7.0.0"
2454+
24472455
babel-plugin-lodash@^3.3.4:
24482456
version "3.3.4"
24492457
resolved "https://registry.yarnpkg.com/babel-plugin-lodash/-/babel-plugin-lodash-3.3.4.tgz#4f6844358a1340baed182adbeffa8df9967bc196"
@@ -9214,7 +9222,7 @@ yargs@^13.3.2:
92149222
y18n "^4.0.0"
92159223
yargs-parser "^13.1.2"
92169224

9217-
yargs@^17.0.0:
9225+
yargs@^17.0.0, yargs@^17.1.0:
92189226
version "17.1.0"
92199227
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.1.0.tgz#0cd9827a0572c9a1795361c4d1530e53ada168cf"
92209228
integrity sha512-SQr7qqmQ2sNijjJGHL4u7t8vyDZdZ3Ahkmo4sc1w5xI9TBX0QDdG/g4SFnxtWOsGLjwHQue57eFALfwFCnixgg==

0 commit comments

Comments
 (0)