Skip to content

Commit 9e1e02c

Browse files
committed
Continue some version upgrades and tune webpack config for v5
1 parent 4dfd3e3 commit 9e1e02c

File tree

10 files changed

+191
-257
lines changed

10 files changed

+191
-257
lines changed

demo/index.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import { AppContainer } from 'react-hot-loader';
43
import { ExampleApp } from './ExampleApp';
54

65
const APP_ELEMENT = document.getElementById('app')!;
76
const render = (Component: React.ComponentClass<any>) => {
8-
ReactDOM.render(
9-
<AppContainer>
10-
<Component />
11-
</AppContainer>,
12-
APP_ELEMENT,
13-
);
7+
ReactDOM.render(<Component />, APP_ELEMENT);
148
};
159

1610
render(ExampleApp);
17-
18-
declare var module: any;
19-
if (module.hot) {
20-
module.hot.accept('./ExampleApp', () => {
21-
render(require('./ExampleApp').ExampleApp);
22-
});
23-
}

package.json

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"version": "npm-run-all test bundle && git add -A docs/"
4141
},
4242
"dependencies": {
43-
"classnames": "^2.3.1",
43+
"classnames": "^2.3.2",
4444
"immutability-helper": "^3.1.1",
4545
"lodash": "^4.17.21",
4646
"prop-types": "^15.8.1",
@@ -52,23 +52,22 @@
5252
"uuid": "^9.0.0"
5353
},
5454
"devDependencies": {
55-
"@blueprintjs/core": "^4.7.0",
56-
"@blueprintjs/icons": "^4.4.0",
55+
"@blueprintjs/core": "^4.15.1",
56+
"@blueprintjs/icons": "^4.13.1",
57+
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
5758
"@types/chai": "^4.3.0",
5859
"@types/classnames": "^2.3.1",
5960
"@types/dom4": "^2.0.2",
60-
"@types/lodash": "^4.14.180",
61-
"@types/mocha": "^5.2.7",
62-
"@types/prop-types": "^15.7.4",
63-
"@types/react": "^18.0.15",
64-
"@types/react-dom": "^18.0.6",
65-
"@types/react-hot-loader": "^4.1.1",
66-
"@types/uuid": "^3.4.10",
61+
"@types/lodash": "^4.14.191",
62+
"@types/mocha": "^7.0.2",
63+
"@types/prop-types": "^15.7.5",
64+
"@types/react": "^18.0.28",
65+
"@types/react-dom": "^18.0.10",
66+
"@types/uuid": "^9.0.0",
6767
"@types/webpack": "^5.28.0",
6868
"chai": "^4.3.6",
6969
"css-loader": "^6.7.3",
7070
"dnd-core": "16.0.1",
71-
"file-loader": "^6.2.0",
7271
"html-loader": "^4.2.0",
7372
"html-webpack-plugin": "^5.5.0",
7473
"jsdom": "^15.2.1",
@@ -82,7 +81,7 @@
8281
"prettier": "^2.6.1",
8382
"react": "^18.2.0",
8483
"react-dom": "^18.2.0",
85-
"react-hot-loader": "^4.13.1",
84+
"react-refresh": "^0.14.0",
8685
"source-map-loader": "^4.0.1",
8786
"style-loader": "^3.3.1",
8887
"ts-loader": "^9.4.2",
@@ -91,11 +90,11 @@
9190
"tslint-config-prettier": "^1.18.0",
9291
"tslint-plugin-prettier": "^2.3.0",
9392
"tslint-react": "^5.0.0",
94-
"typescript": "^4.6.3",
93+
"typescript": "^4.9.5",
9594
"webpack": "^5.75.0",
9695
"webpack-cli": "^5.0.1",
9796
"webpack-dev-server": "^4.11.1",
98-
"yarn-deduplicate": "^3.1.0"
97+
"yarn-deduplicate": "^6.0.1"
9998
},
10099
"peerDependencies": {
101100
"react": "16 - 18"

src/MosaicDropTarget.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export function MosaicDropTarget({ path, position }: MosaicDropTargetProps) {
1515
const { mosaicId } = useContext(MosaicContext);
1616
const [{ isOver, draggedMosaicId }, connectDropTarget] = useDrop({
1717
accept: MosaicDragType.WINDOW,
18-
drop: (item: MosaicDragItem, _monitor): MosaicDropData => {
19-
if (mosaicId === (item || {}).mosaicId) {
18+
drop: (item: MosaicDragItem | undefined, _monitor): MosaicDropData => {
19+
if (mosaicId === item?.mosaicId) {
2020
return { path, position };
2121
} else {
2222
return {};

src/MosaicWindow.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function ConnectedInternalMosaicWindow<T extends MosaicKey = string>(props: Inte
258258
// The defer is necessary as the element must be present on start for HTML DnD to not cry
259259
const hideTimer = defer(() => mosaicActions.hide(props.path));
260260
return {
261-
mosaicId: mosaicId,
261+
mosaicId,
262262
hideTimer,
263263
};
264264
},
@@ -296,12 +296,10 @@ function ConnectedInternalMosaicWindow<T extends MosaicKey = string>(props: Inte
296296

297297
const [{ isOver, draggedMosaicId }, connectDropTarget] = useDrop({
298298
accept: MosaicDragType.WINDOW,
299-
collect(monitor: DropTargetMonitor<MosaicDragItem>) {
300-
return {
301-
isOver: monitor.isOver(),
302-
draggedMosaicId: (monitor.getItem() || {}).mosaicId,
303-
};
304-
},
299+
collect: (monitor: DropTargetMonitor<MosaicDragItem>) => ({
300+
isOver: monitor.isOver(),
301+
draggedMosaicId: monitor.getItem()?.mosaicId,
302+
}),
305303
});
306304
return (
307305
<InternalMosaicWindow

src/RootDropTargets.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { MosaicDragType } from './types';
1010
export const RootDropTargets = React.memo(() => {
1111
const [{ isDragging }] = useDrop({
1212
accept: MosaicDragType.WINDOW,
13-
collect(monitor) {
14-
return { isDragging: monitor.getItem() !== null && monitor.getItemType() === MosaicDragType.WINDOW };
15-
},
13+
collect: (monitor) => ({
14+
isDragging: monitor.getItem() !== null && monitor.getItemType() === MosaicDragType.WINDOW,
15+
}),
1616
});
1717
const delayedIsDragging = useDelayedTrue(isDragging, 0);
1818
return (

webpack/base.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ import HtmlWebpackPlugin from 'html-webpack-plugin';
22
import webpack from 'webpack';
33
import { CONSTANTS } from './constants';
44

5-
// tslint:disable-next-line no-var-requires
6-
const VENDOR_LIBS = Object.keys(require('../package.json').dependencies);
7-
85
const config: webpack.Configuration = {
9-
entry: {
10-
app: CONSTANTS.APP_ENTRY,
11-
vendor: VENDOR_LIBS,
12-
},
6+
entry: CONSTANTS.APP_ENTRY,
137
output: {
148
filename: '[name].js',
159
path: CONSTANTS.DOCS_DIR,
@@ -19,7 +13,7 @@ const config: webpack.Configuration = {
1913
extensions: ['.webpack.js', '.web.js', '.json', '.ts', '.js', '.tsx'],
2014
},
2115
optimization: {
22-
moduleIds: 'named'
16+
moduleIds: 'named',
2317
},
2418
module: {
2519
rules: [
@@ -58,7 +52,7 @@ const config: webpack.Configuration = {
5852
},
5953
{
6054
test: /\.jpe?g$|\.gif$|\.png$|\.svg$|\.woff2?$|\.ttf$|\.eot$/,
61-
loader: 'file-loader',
55+
type: 'asset/resource',
6256
},
6357
{
6458
test: /\.less/,

webpack/bundle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import config from './base';
33

44
const bundleConfig: webpack.Configuration = {
55
...config,
6+
mode: 'production',
67
optimization: {
78
...config.optimization,
89
minimize: true,

webpack/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export const CONSTANTS = {
66
HTML_TEMPLATE: path.join(__dirname, 'index-template.html'),
77
DOCS_DIR: path.join(__dirname, '..', 'docs/'),
88
DEV_SERVER_PORT: 8092,
9+
PUBLIC_PATH: '/public/',
910
};

webpack/hot.ts

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,12 @@
1+
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
12
import webpack from 'webpack';
3+
import 'webpack-dev-server';
24
import config from './base';
35
import { CONSTANTS } from './constants';
4-
import 'webpack-dev-server';
5-
6-
const baseEntry = config.entry as webpack.EntryObject;
7-
const entry = {
8-
...baseEntry,
9-
app: [
10-
// activate HMR for React
11-
'react-hot-loader/patch',
12-
13-
// bundle the client for webpack-dev-server
14-
// and connect to the provided endpoint
15-
'webpack-dev-server/client?http://localhost:' + CONSTANTS.DEV_SERVER_PORT,
16-
17-
// bundle the client for hot reloading
18-
// only- means to only hot reload for successful updates
19-
'webpack/hot/only-dev-server',
20-
baseEntry.app as string,
21-
],
22-
};
23-
24-
const rules = (config.module as webpack.ModuleOptions).rules?.map((loaderConf: any) => {
25-
if (loaderConf.test.test('test.ts')) {
26-
return {
27-
...loaderConf,
28-
use: [
29-
{
30-
loader: 'react-hot-loader/webpack',
31-
},
32-
...loaderConf.use,
33-
],
34-
};
35-
} else {
36-
return loaderConf;
37-
}
38-
});
39-
const module = {
40-
...config.module,
41-
rules,
42-
};
436

447
const hotConfig: webpack.Configuration = {
458
...config,
469
mode: 'development',
47-
entry,
48-
module,
4910
devtool: 'cheap-module-source-map',
5011
stats: 'minimal',
5112
optimization: {
@@ -57,8 +18,8 @@ const hotConfig: webpack.Configuration = {
5718
hot: true,
5819
host: '0.0.0.0',
5920
port: CONSTANTS.DEV_SERVER_PORT,
60-
open: true,
6121
},
22+
plugins: [...(config.plugins || []), new ReactRefreshWebpackPlugin()],
6223
};
6324

6425
// tslint:disable-next-line no-default-export

0 commit comments

Comments
 (0)