Skip to content

Commit 2cae5a4

Browse files
eric-parsonsianschmitzEric Parsons
authored
feat: Webpack 5 (#34)
* fix: update to webpack 5 * Updating dev server and other dependencies. * Post MUI-5 styling fix. * Running Prettier. * Fixing tests. * retrigger checks * Replacing non-functional semantic pull requests Co-authored-by: Ian Schmitz <ianschmitz@gmail.com> Co-authored-by: Eric Parsons <eparsons@latitudegeo.com>
1 parent 69c0633 commit 2cae5a4

File tree

13 files changed

+104
-126
lines changed

13 files changed

+104
-126
lines changed

.github/semantic.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/workflows/ci-cd.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v2
2323

24-
- name: Use Node.js 12
24+
- name: Use Node.js 14
2525
uses: actions/setup-node@v1
2626
with:
27-
node-version: 12.x
27+
node-version: 14.x
2828

2929
- run: npm install
3030

@@ -47,10 +47,10 @@ jobs:
4747
- name: Fetch git tags
4848
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
4949

50-
- name: Use Node.js 12
50+
- name: Use Node.js 14
5151
uses: actions/setup-node@v1
5252
with:
53-
node-version: 12.x
53+
node-version: 14.x
5454

5555
- run: npm install
5656
env:

.github/workflows/lint-pr.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: "Lint PR"
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
jobs:
11+
main:
12+
name: Validate PR title
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: amannn/action-semantic-pull-request@v4
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

config/paths.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const resolveModule = (resolveFn, filePath) => {
2323
};
2424
const resolveProj = (relativePath) => path.resolve(projRoot, relativePath);
2525
// Up 1 from "config/"
26-
const resolveOwn = (relativePath) => path.resolve(__dirname, "..", relativePath);
26+
const resolveOwn = (relativePath) =>
27+
path.resolve(__dirname, "..", relativePath);
2728

2829
module.exports = {
2930
projBuild: resolveProj("build"),

config/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"compilerOptions": {
33
"module": "esnext",
4-
"target": "es2019",
5-
"lib": ["es2019", "dom", "dom.iterable"],
4+
"target": "es2021",
5+
"lib": ["es2021", "dom", "dom.iterable"],
66
"allowJs": true,
77
// Assumes <projectdir>/node_modules/@vertigis/web-sdk/config
88
"baseUrl": "../../../../",
@@ -19,6 +19,7 @@
1919
},
2020
"resolveJsonModule": true,
2121
"skipLibCheck": true,
22+
"sourceMap": true,
2223
"strict": true,
2324
"strictNullChecks": false,
2425
"strictFunctionTypes": false,

config/webpack.config.js

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ const path = require("path");
66
const paths = require("./paths");
77
const webpack = require("webpack");
88

9-
const autoprefixer = require("autoprefixer");
109
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
1110
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
1211
const HtmlWebPackPlugin = require("html-webpack-plugin");
13-
const TerserPlugin = require("terser-webpack-plugin");
1412

1513
const isEnvDevelopment = process.env.NODE_ENV === "development";
1614
const isEnvProduction = process.env.NODE_ENV === "production";
@@ -23,11 +21,12 @@ const libId = require("crypto").randomBytes(8).toString("hex");
2321
module.exports = {
2422
mode: isEnvProduction ? "production" : "development",
2523
context: paths.projRoot,
26-
devtool: isEnvProduction ? false : "eval",
24+
devtool: isEnvProduction
25+
? false
26+
: process.env.DEV_TOOL || "inline-source-map",
2727
// Disable perf hints as it's mostly out of the developer's control as we
2828
// only allow one chunk.
2929
performance: false,
30-
stats: "minimal",
3130
resolve: {
3231
extensions: paths.moduleFileExtensions,
3332
alias: {
@@ -46,25 +45,16 @@ module.exports = {
4645
// Technically this shouldn't be needed as we restrict the library to
4746
// one chunk, but we set this here just to be extra safe against
4847
// collisions.
49-
jsonpFunction: libId,
48+
chunkLoadingGlobal: libId,
5049
libraryTarget: "amd",
5150
// Use "/" in dev so hot updates are requested from server root instead
5251
// of from "viewer" relative path.
5352
publicPath: isEnvProduction ? "." : "/",
5453
path: isEnvProduction ? paths.projBuild : undefined,
55-
// TODO: remove this when upgrading to webpack 5
56-
futureEmitAssets: true,
5754
// There will be one main bundle, and one file per asynchronous chunk.
5855
// In development, it does not produce real files.
5956
filename: "[name].js",
6057
},
61-
optimization: {
62-
// This is only used in production mode
63-
minimizer: [
64-
// Minify JS output
65-
new TerserPlugin(),
66-
],
67-
},
6858
module: {
6959
strictExportPresence: true,
7060
rules: [
@@ -78,9 +68,6 @@ module.exports = {
7868
{
7969
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
8070
loader: require.resolve("url-loader"),
81-
options: {
82-
esModule: true,
83-
},
8471
},
8572
// Process application JS with Babel.
8673
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
@@ -99,9 +86,6 @@ module.exports = {
9986
use: [
10087
{
10188
loader: require.resolve("style-loader"),
102-
options: {
103-
esModule: true,
104-
},
10589
},
10690
{
10791
loader: require.resolve("css-loader"),
@@ -115,20 +99,9 @@ module.exports = {
11599
// package.json
116100
loader: require.resolve("postcss-loader"),
117101
options: {
118-
ident: "postcss",
119-
plugins: () =>
120-
[
121-
autoprefixer({
122-
flexbox: "no-2009",
123-
overrideBrowserslist: [
124-
"last 2 chrome versions",
125-
"last 2 firefox versions",
126-
"last 2 safari versions",
127-
],
128-
}),
129-
isEnvProduction &&
130-
require("cssnano")(),
131-
].filter(Boolean),
102+
postcssOptions: {
103+
plugins: ["postcss-preset-env"],
104+
},
132105
},
133106
},
134107
],
@@ -165,12 +138,10 @@ module.exports = {
165138

166139
isEnvProduction && new CleanWebpackPlugin(),
167140
].filter(Boolean),
168-
node: {
169-
dgram: "empty",
170-
fs: "empty",
171-
net: "empty",
172-
tls: "empty",
173-
// eslint-disable-next-line @typescript-eslint/camelcase
174-
child_process: "empty",
141+
watchOptions: {
142+
// Don't bother watching node_modules files for changes. This reduces
143+
// CPU/mem overhead, but means that changes from `npm install` while the
144+
// dev server is running won't take effect until restarted.
145+
ignored: /node_modules/,
175146
},
176147
};

package.json

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,46 @@
2929
"test": "node ./test/index.js"
3030
},
3131
"dependencies": {
32-
"@typescript-eslint/eslint-plugin": "^4.27.0",
33-
"@typescript-eslint/parser": "^4.27.0",
34-
"autoprefixer": "^9.8.6",
32+
"@typescript-eslint/eslint-plugin": "^5.29.0",
33+
"@typescript-eslint/parser": "^5.29.0",
3534
"chalk": "^4.1.0",
36-
"clean-webpack-plugin": "^3.0.0",
37-
"css-loader": "^4.3.0",
38-
"cssnano": "^4.1.10",
39-
"eslint": "^7.28.0",
35+
"clean-webpack-plugin": "^4.0.0",
36+
"css-loader": "^6.7.1",
37+
"eslint": "^8.18.0",
4038
"eslint-config-prettier": "^8.3.0",
4139
"eslint-plugin-react": "^7.24.0",
42-
"eslint-plugin-react-hooks": "^4.2.0",
43-
"fork-ts-checker-webpack-plugin": "^5.2.0",
40+
"eslint-plugin-react-hooks": "^4.6.0",
41+
"fork-ts-checker-webpack-plugin": "^6.2.6",
4442
"fs-extra": "^10.0.0",
45-
"html-webpack-plugin": "^4.5.0",
43+
"html-webpack-plugin": "^5.5.0",
4644
"node-fetch": "^2.6.7",
47-
"open": "^8.2.0",
48-
"postcss-loader": "^3.0.0",
49-
"style-loader": "^1.2.1",
50-
"terser-webpack-plugin": "^4.2.1",
51-
"ts-loader": "^8.0.12",
45+
"postcss-loader": "^7.0.0",
46+
"postcss-preset-env": "^7.7.1",
47+
"style-loader": "^3.3.1",
48+
"terser-webpack-plugin": "^5.3.3",
49+
"ts-loader": "^9.3.0",
5250
"url-loader": "^4.1.1",
53-
"webpack": "^4.44.1",
54-
"webpack-dev-server": "^3.11.0"
51+
"webpack": "^5.73.0",
52+
"webpack-dev-server": "^4.9.2"
5553
},
5654
"devDependencies": {
5755
"@types/node": "^14.14.13",
58-
"@vertigis/web": "^5.16.0",
56+
"@vertigis/web": "^5.17.0",
5957
"conventional-changelog-conventionalcommits": "^4.5.0",
6058
"cross-env": "^7.0.3",
6159
"execa": "^5.1.1",
62-
"husky": "^6.0.0",
63-
"p-retry": "^4.2.0",
64-
"playwright-chromium": "1.12.2",
65-
"prettier": "^2.3.1",
66-
"pretty-quick": "^3.1.0",
67-
"semantic-release": "^17.4.3",
68-
"typescript": "^4.5.5"
60+
"lint-staged": "13.0.2",
61+
"p-retry": "^4.6.2",
62+
"playwright-chromium": "1.22.2",
63+
"prettier": "^2.7.1",
64+
"semantic-release": "^19.0.3",
65+
"simple-git-hooks": "2.8.0",
66+
"typescript": "^4.7.4"
6967
},
70-
"husky": {
71-
"hooks": {
72-
"pre-commit": "pretty-quick --staged"
73-
}
68+
"simple-git-hooks": {
69+
"pre-commit": "npx lint-staged"
70+
},
71+
"lint-staged": {
72+
"*.{js,json,ts,tsx,md,xml}": "prettier --write"
7473
}
7574
}

scripts/build.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,10 @@ const build = () => {
2929

3030
console.log(
3131
stats.toString({
32-
// TODO: Use "preset" property instead when webpack 5 is released.
33-
// Copied from `minimal` preset.
34-
all: false,
35-
modules: true,
36-
maxModules: 0,
37-
errors: true,
38-
warnings: true,
39-
40-
// Add in assets output to see chunk size.
41-
assets: true,
32+
preset: "normal",
33+
colors: chalk.supportsColor
34+
? chalk.supportsColor.hasBasic
35+
: false,
4236
})
4337
);
4438

@@ -87,7 +81,7 @@ const build = () => {
8781
await build();
8882
} catch (e) {
8983
if (e && e.message) {
90-
console.error(e.message);
84+
console.error(e);
9185
}
9286
process.exit(1);
9387
}

scripts/start.js

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ process.on("unhandledRejection", (err) => {
1414

1515
const http = require("http");
1616
const https = require("https");
17-
const open = require("open");
1817
const webpack = require("webpack");
1918
const WebpackDevServer = require("webpack-dev-server");
2019
const paths = require("../config/paths");
@@ -29,21 +28,23 @@ const port = process.env.PORT || 3000;
2928

3029
const compiler = webpack(webpackConfig);
3130
const serverConfig = {
32-
after: function () {
33-
if (process.env.OPEN_BROWSER !== "false") {
34-
open(`http://localhost:${port}${process.env.OPEN_PAGE || ""}`);
35-
}
31+
allowedHosts: "all",
32+
client: {
33+
logging: "none",
34+
webSocketURL: {
35+
port: process.env.SOCK_PORT || undefined,
36+
},
3637
},
37-
clientLogLevel: "silent",
3838
compress: true,
39-
contentBase: paths.projPublicDir,
40-
disableHostCheck: true,
4139
headers: {
4240
"Access-Control-Allow-Origin": "*",
4341
},
4442
// Allow binding to any host (localhost, jdoe-pc.latitudegeo.com, etc).
4543
host: "0.0.0.0",
4644
hot: true,
45+
open:
46+
process.env.OPEN_BROWSER !== "false" &&
47+
`http://localhost:${port}${process.env.OPEN_PAGE || ""}`,
4748
port,
4849
proxy: {
4950
"/viewer": {
@@ -58,28 +59,10 @@ const serverConfig = {
5859
},
5960
},
6061
},
61-
sockPort: process.env.SOCK_PORT || undefined,
62-
stats: "minimal",
63-
watchContentBase: true,
64-
watchOptions: {
65-
// Don't bother watching node_modules files for changes. This reduces
66-
// CPU/mem overhead, but means that changes from `npm install` while the
67-
// dev server is running won't take effect until restarted.
68-
ignored: /node_modules/,
62+
static: {
63+
directory: paths.projPublicDir,
6964
},
7065
};
7166

72-
const devServer = new WebpackDevServer(compiler, serverConfig);
73-
devServer.listen(serverConfig.port, serverConfig.host, (err) => {
74-
if (err) {
75-
throw err;
76-
}
77-
});
78-
79-
["SIGINT", "SIGTERM"].forEach((signal) => {
80-
process.on(signal, () => {
81-
devServer.close(() => {
82-
process.exit();
83-
});
84-
});
85-
});
67+
const devServer = new WebpackDevServer(serverConfig, compiler);
68+
devServer.start();

template/src/components/PointsOfInterest/PointOfInterest.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
height: 20px;
33
width: 20px;
44
border-radius: 50%;
5+
margin-right: 16px;
56
}

0 commit comments

Comments
 (0)