Skip to content

Commit 4d6b973

Browse files
build: Migrate from Webpack to Vite (closes #146, resolves #238). (#175)
Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>
1 parent 3be9e01 commit 4d6b973

26 files changed

+1976
-6362
lines changed

docs/src/dev-guide/building-getting-started.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ variable `NODE_ENV=production` is set.
2121
You can build and serve the viewer in debug mode using:
2222

2323
```shell
24-
npm start
24+
npm run dev
2525
```
2626

2727
The viewer should then be available at [http://localhost:3010](http://localhost:3010).
@@ -36,6 +36,17 @@ npm run build
3636

3737
The build should then be available in the `dist` directory.
3838

39+
## Previewing the Build
40+
41+
To preview the production build locally, run:
42+
43+
```shell
44+
npm run preview
45+
```
46+
47+
This will serve the contents of the `dist` directory using Vite’s preview server, which simulates
48+
how the app will behave in production.
49+
3950
[nodejs-prebuilt-installer]: https://nodejs.org/en/download/prebuilt-installer
4051
[nvm]: https://github.com/nvm-sh/nvm
4152
[nvm-windows]: https://github.com/coreybutler/nvm-windows

docs/src/dev-guide/coding-guidelines.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,31 @@
33
This project adheres to YScope's [contribution guidelines][yscope-guidelines] as well as the
44
project-specific guidelines below.
55

6+
# Web workers
7+
8+
## Importing web workers
9+
10+
When importing web worker files, use Vite's `?worker` query suffix syntax:
11+
12+
```ts
13+
import MainWorker from "../services/MainWorker.worker?worker";
14+
15+
const worker = new MainWorker();
16+
```
17+
18+
This special syntax tells Vite to transform the import as a web worker constructor. See
19+
[Vite's web worker documentation][vite-worker-query-suffix] for more details.
20+
621
# Naming
722

23+
## Web worker files
24+
25+
Name web worker files with the extension, `.worker.ts`. This is to:
26+
27+
* follow standard practices.
28+
* allow [eslint.config.mjs][eslint-config-mjs] to ignore `.worker.ts` files, suppressing
29+
`eslint-plugin-import:import/default` errors caused by Vite's `?worker` import syntax.
30+
831
## Index variables
932

1033
To differentiate variables that use different starting indexes (0 vs. 1), use the following naming
@@ -30,4 +53,6 @@ To avoid including a state variable in a React Hook's dependency array, you can
3053
the state variable with an additional `Ref` suffix. E.g., `logEventNumRef` is the reference variable
3154
that corresponds to the `logEventNum` state variable.
3255

56+
[eslint-config-mjs]: https://github.com/y-scope/yscope-log-viewer/blob/main/eslint.config.mjs
57+
[vite-worker-query-suffix]: https://vite.dev/guide/features.html#import-with-query-suffixes
3358
[yscope-guidelines]: https://docs.yscope.com/dev-guide/contrib-guides-overview.html

docs/src/dev-guide/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Docs about the viewer's design.
3535
:hidden:
3636

3737
building-getting-started
38+
optimization-guide
3839
:::
3940

4041
:::{toctree}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Optimization guide
2+
3+
This doc outlines strategies and tools used to optimize the build's size and load time.
4+
5+
## Bundle analysis
6+
7+
To generate a bundle analysis report, run:
8+
9+
```shell
10+
# You may be prompted to install `vite-bundle-visualizer`. Accept the prompt to install it.
11+
npm run analyze:size
12+
```
13+
14+
This will use [`vite-bundle-visualizer`][vite-bundle-visualizer] to generate an interactive visual
15+
breakdown of bundle contents, helping identify large dependencies and optimization opportunities.
16+
17+
## Future strategies
18+
19+
The following optimization strategies are planned for the future:
20+
21+
* **Code splitting**: We can split the code into smaller chunks to improve load time, especially
22+
when using lazy loading.
23+
* **Lazy loading**: We can load components or modules only when they are needed. This can be
24+
achieved by using dynamic imports or React's `lazy()` and `Suspense` features.
25+
26+
[vite-bundle-visualizer]: https://www.npmjs.com/package/vite-bundle-visualizer

eslint.config.mjs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import CommonConfig from "eslint-config-yscope/CommonConfig.mjs";
22
import JestConfig from "eslint-config-yscope/JestConfig.mjs";
33
import ReactConfigArray from "eslint-config-yscope/ReactConfigArray.mjs";
44
import StylisticConfigArray from "eslint-config-yscope/StylisticConfigArray.mjs";
5-
import TsConfigArray from "eslint-config-yscope/TsConfigArray.mjs";
6-
import Globals from "globals";
5+
import TsConfigArray, {createTsConfigOverride} from "eslint-config-yscope/TsConfigArray.mjs";
76

87

98
const EslintConfig = [
@@ -14,7 +13,24 @@ const EslintConfig = [
1413
],
1514
},
1615
CommonConfig,
16+
1717
...TsConfigArray,
18+
createTsConfigOverride(
19+
[
20+
"src/**/*.ts",
21+
"src/**/*.tsx",
22+
"test/**/*.ts",
23+
],
24+
"tsconfig.app.json"
25+
),
26+
createTsConfigOverride(
27+
[
28+
"jest.config.ts",
29+
"vite.config.ts",
30+
],
31+
"tsconfig.node.json"
32+
),
33+
1834
...StylisticConfigArray,
1935
...ReactConfigArray,
2036
{
@@ -41,13 +57,11 @@ const EslintConfig = [
4157
},
4258
],
4359
},
44-
},
45-
{
46-
files: ["webpack.*.js"],
47-
languageOptions: {
48-
globals: {
49-
...Globals.node,
50-
},
60+
settings: {
61+
// Rule "import/default" complains on Vite's web worker import directives.
62+
"import/ignore": [
63+
"\\.worker",
64+
],
5165
},
5266
},
5367
{
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<title>Log Viewer</title>
5-
<meta charset="utf-8">
5+
<meta charset="UTF-8" />
6+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
67
<meta name="description" content="YScope Log Viewer">
78
<meta name="keywords"
89
content="yscope clp debug debugging large log logs s3 scanner viewer vscode">
9-
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
10+
<meta name="viewport" content="initial-scale=1, maximum-scale=1, width=device-width" />
1011
<link rel="preconnect" href="https://fonts.googleapis.com">
1112
<link rel="preconnect" crossorigin href="https://fonts.gstatic.com">
1213
<link rel="stylesheet"
@@ -16,5 +17,6 @@
1617
</head>
1718
<body>
1819
<div id="root"></div>
20+
<script type="module" src="/src/main.tsx"></script>
1921
</body>
2022
</html>

jest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import os from "node:os";
2-
import pathPosix from "node:path/posix";
1+
import * as os from "node:os";
2+
import * as pathPosix from "node:path/posix";
33

44
import type {Config} from "jest";
55

0 commit comments

Comments
 (0)