Skip to content

build: Migrate from Webpack to Vite (closes #146, resolves #238). #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 63 commits into from
May 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
49ab69f
build: migrate from Webpack to Vite.
junhaoliao Feb 3, 2025
35aabf2
Add comment to explain why adding import/ignore to eslint settings.
junhaoliao Feb 3, 2025
b1a7f46
Add test folder to ESLint configuration.
junhaoliao Feb 3, 2025
44ddeb4
Add Jest config to TypeScript overrides in ESLint setup
junhaoliao Feb 3, 2025
98687b6
Add jest.config.ts to tsconfig.node.json include list
junhaoliao Feb 3, 2025
dcdc4b1
Refactor MainWorker imports to use renamed worker file
junhaoliao Feb 3, 2025
2d7b02a
Fix syntax for accessing environment variables
junhaoliao Feb 3, 2025
d5e189c
Refactor timestamp handling to use bigint type
junhaoliao Feb 3, 2025
221074d
Disable `noPropertyAccessFromIndexSignature` in tsconfig.
junhaoliao Feb 3, 2025
48aed37
Add `esModuleInterop` to `tsconfig.node.json` to improve module compa…
junhaoliao Feb 3, 2025
83c57c2
Update favicon path in index.html
junhaoliao Feb 3, 2025
a7269a8
Update viewport meta tag in index.html
junhaoliao Feb 3, 2025
ff935ad
Add back meta "keywords" in index.html
junhaoliao Feb 3, 2025
2097bbc
Update build doc for running the debug server.
junhaoliao Feb 12, 2025
7edd320
Merge remote-tracking branch 'yscope/main' into vite
junhaoliao Feb 12, 2025
cb37747
Refactor Monaco imports and remove obsolete Rollup externals.
junhaoliao Feb 12, 2025
9124e3d
Optimize build by splitting monaco-editor into a separate chunk.
junhaoliao Feb 12, 2025
da2ecd7
Set relative base path in Vite configuration.
junhaoliao Feb 12, 2025
a46a36b
Enable sourcemaps.
junhaoliao Feb 12, 2025
95df1e0
Add "type": "module" to package.json.
junhaoliao Feb 12, 2025
139d161
Remove standalone README for MonacoInstance and add bootstrap import.
junhaoliao Feb 14, 2025
c8184c8
Disable and re-enable ESLint rule for maximum line length.
junhaoliao Feb 14, 2025
4e7c916
Reorder.
junhaoliao Feb 14, 2025
bb7a380
Set assetsDir to empty string in Vite config.
junhaoliao Feb 14, 2025
1bae57d
Update Vite to version 6.1.0.
junhaoliao Feb 14, 2025
cd5c0bf
Add comment to explain purpose of the new bootstrap.ts.
junhaoliao Feb 14, 2025
ce20db7
Remove monaco bootstrap import in main.tsx.
junhaoliao Feb 14, 2025
9d4651e
Merge remote-tracking branch 'yscope/main' into vite
junhaoliao Mar 10, 2025
011f7fa
Upgrade Vite version to the latest.
junhaoliao Mar 10, 2025
866c5e8
Merge branch 'main' into fork/junhaoliao/vite
Henry8192 Mar 27, 2025
26280ba
Merge remote-tracking branch 'yscope/main' into vite
junhaoliao Apr 3, 2025
a866b3f
chore: Upgrade Vite to version 6.2.5
junhaoliao Apr 3, 2025
a751770
Merge branch 'main' into vite
junhaoliao Apr 12, 2025
0bd761f
Merge branch 'main' into vite
junhaoliao Apr 14, 2025
8d92be9
chore: Upgrade Vite to version 6.2.6
junhaoliao Apr 14, 2025
f234101
Merge branch 'main' into vite
junhaoliao Apr 14, 2025
32c3ad3
docs: Update comments for Vite's web worker support in bootstrap.ts
junhaoliao Apr 21, 2025
664e02f
docs: Add guidelines for naming web worker files and importing with Vite
junhaoliao Apr 22, 2025
042fc29
refactor: remove redundant bigint cast.
junhaoliao Apr 22, 2025
08be042
Update debug server start command in docs - Apply suggestions from co…
junhaoliao Apr 22, 2025
e891f11
refactor: remove jest.config.ts from tsconfig.app.json include.
junhaoliao Apr 22, 2025
1cc0430
docs: Add clarification on SPA behavior for non-existent paths in vit…
junhaoliao Apr 22, 2025
928739d
docs: Clarify base path behavior in vite.config.ts
junhaoliao Apr 22, 2025
4dc9612
docs: Add comments to vite.config.ts for manual chunks and optimizeDeps
junhaoliao Apr 22, 2025
494172b
docs: Add instructions for previewing the production build locally
junhaoliao Apr 22, 2025
a6b156e
chore: update Vite React plugin to use SWC edition
junhaoliao Apr 22, 2025
b05ed86
Merge branch 'main' into vite
junhaoliao Apr 22, 2025
15b7db2
Change article in docs - Apply suggestions from code review
junhaoliao Apr 28, 2025
d030fb1
Improve inline docs for MonacoInstance/boostrap.ts - Apply suggestion…
junhaoliao Apr 29, 2025
bfbd033
docs: Update coding guidelines for Web Workers - Split import syntax …
junhaoliao Apr 29, 2025
0cbd976
Improve Vite's appType config inline docs: Apply suggestions from cod…
junhaoliao Apr 29, 2025
2b4d222
Improve clp-ffi-js dep opt docs - Apply suggestions from code review
junhaoliao Apr 29, 2025
9624822
Merge branch 'main' into vite
junhaoliao Apr 29, 2025
778f4c4
chore: update vite to version 6.3.3 and fdir to version 6.4.4
junhaoliao Apr 29, 2025
8d8b7e1
docs: add optimization guide for bundle size and load time strategies
junhaoliao Apr 29, 2025
ee1483a
feat: add script to analyze bundle size using vite-bundle-visualizer
junhaoliao Apr 29, 2025
3c1660f
docs: update optimization guide title and add to navigation
junhaoliao Apr 29, 2025
e2c1387
Merge branch 'main' into vite
junhaoliao May 12, 2025
f2aba14
Docs - Apply suggestions from code review
junhaoliao May 12, 2025
8597850
docs: Standardize capitalization of "web worker" in guidelines and ES…
junhaoliao May 12, 2025
fa9090c
Remove docs for rollupOptions.output - Apply suggestions from code re…
junhaoliao May 12, 2025
cb015ec
docs: Add note about installing vite-bundle-visualizer for bundle ana…
junhaoliao May 17, 2025
abdec7e
Merge branch 'main' into vite
junhaoliao May 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/src/dev-guide/building-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ variable `NODE_ENV=production` is set.
You can build and serve the viewer in debug mode using:

```shell
npm start
npm run dev
```

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

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

## Previewing the Build

To preview the production build locally, run:

```shell
npm run preview
```

This will serve the contents of the `dist` directory using Vite’s preview server, which simulates
how the app will behave in production.

[nodejs-prebuilt-installer]: https://nodejs.org/en/download/prebuilt-installer
[nvm]: https://github.com/nvm-sh/nvm
[nvm-windows]: https://github.com/coreybutler/nvm-windows
25 changes: 25 additions & 0 deletions docs/src/dev-guide/coding-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,31 @@
This project adheres to YScope's [contribution guidelines][yscope-guidelines] as well as the
project-specific guidelines below.

# Web workers
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Standardize capitalization of "web workers"

Be consistent with capitalization. Past discussions indicated "web workers" should not be treated as a proper noun. Use lowercase "web workers" throughout the document.

- # Web workers
+ # web workers

- When importing web worker files, use Vite's `?worker` query suffix syntax:
+ When importing web worker files, use Vite's `?worker` query suffix syntax:

- This special syntax tells Vite to transform the import as a web worker constructor. See
+ This special syntax tells Vite to transform the import as a web worker constructor. See

Also applies to: 10-10, 18-18

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

6-6: Multiple top-level headings in the same document
null

(MD025, single-title, single-h1)


## Importing web workers

When importing web worker files, use Vite's `?worker` query suffix syntax:

```ts
import MainWorker from "../services/MainWorker.worker?worker";

const worker = new MainWorker();
```

This special syntax tells Vite to transform the import as a web worker constructor. See
[Vite's web worker documentation][vite-worker-query-suffix] for more details.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Link to specific section in Vite documentation

Consider linking directly to the specific section in Vite's documentation about workers for easier reference.

- [Vite's web worker documentation][vite-worker-query-suffix] for more details.
+ [Vite's web worker documentation][vite-worker-query-suffix#web-workers] for more details.

Then update the link reference:

- [vite-worker-query-suffix]: https://vite.dev/guide/features.html#import-with-query-suffixes
+ [vite-worker-query-suffix]: https://vitejs.dev/guide/features.html#web-workers
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[Vite's web worker documentation][vite-worker-query-suffix] for more details.
[Vite's web worker documentation][vite-worker-query-suffix#web-workers] for more details.
[...]
[vite-worker-query-suffix]: https://vitejs.dev/guide/features.html#web-workers


# Naming

## Web worker files

Name web worker files with the extension, `.worker.ts`. This is to:

* follow standard practices.
* allow [eslint.config.mjs][eslint-config-mjs] to ignore `.worker.ts` files, suppressing
`eslint-plugin-import:import/default` errors caused by Vite's `?worker` import syntax.
Comment on lines +25 to +29
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Refine bullet list for clarity and grammar

The phrasing can be tightened. For example:

- Name web worker files with the extension, `.worker.ts`. This is to:
+ Name web worker files with the extension `.worker.ts` to:

- * follow standard practices.
+ * follow standard practices
- * allow [eslint.config.mjs][eslint-config-mjs] to ignore `.worker.ts` files, suppressing
-  `eslint-plugin-import:import/default` errors caused by Vite's `?worker` import syntax.
+ * allow [eslint.config.mjs][eslint-config-mjs] to ignore `.worker.ts` files and suppress
+   `eslint-plugin-import:import/default` errors caused by Vite’s `?worker` import syntax
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Name web worker files with the extension, `.worker.ts`. This is to:
* follow standard practices.
* allow [eslint.config.mjs][eslint-config-mjs] to ignore `.worker.ts` files, suppressing
`eslint-plugin-import:import/default` errors caused by Vite's `?worker` import syntax.
Name web worker files with the extension `.worker.ts` to:
* follow standard practices
* allow [eslint.config.mjs][eslint-config-mjs] to ignore `.worker.ts` files and suppress
`eslint-plugin-import:import/default` errors caused by Vites `?worker` import syntax


## Index variables

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

[eslint-config-mjs]: https://github.com/y-scope/yscope-log-viewer/blob/main/eslint.config.mjs
[vite-worker-query-suffix]: https://vite.dev/guide/features.html#import-with-query-suffixes
[yscope-guidelines]: https://docs.yscope.com/dev-guide/contrib-guides-overview.html
1 change: 1 addition & 0 deletions docs/src/dev-guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Docs about the viewer's design.
:hidden:

building-getting-started
optimization-guide
:::

:::{toctree}
Expand Down
26 changes: 26 additions & 0 deletions docs/src/dev-guide/optimization-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Optimization guide
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Nitpick: Consistent title casing
Consider using title case for the main heading—e.g. “Optimization Guide” instead of “Optimization guide”—to align with other guide titles in the documentation.


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider cross-linking related guides
You might add a link to the “Building & Getting Started” guide for better navigation. For example:

+# See the [Building & Getting Started](../building-getting-started.md) guide for setup instructions.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# See the [Building & Getting Started](../building-getting-started.md) guide for setup instructions.

This doc outlines strategies and tools used to optimize the build's size and load time.

Comment on lines +3 to +4
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Enhance navigation with cross-links and refine wording

  • Rephrase to “optimize build size and load time” instead of “optimize the build's size and load time.”
  • Add a link to the Building & Getting Started guide for smoother onboarding. E.g.:
-This doc outlines strategies and tools used to optimize build size and load time.
+# This doc outlines strategies and tools used to optimize build size and load time.
+
+# See the [Building & Getting Started](../building-getting-started.md) guide for setup instructions.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In docs/src/dev-guide/optimization-guide.md around lines 3 to 4, rephrase the
sentence to say "optimize build size and load time" instead of "optimize the
build's size and load time." Additionally, add a hyperlink to the Building &
Getting Started guide within the text to improve navigation and onboarding for
readers.

## Bundle analysis

To generate a bundle analysis report, run:

```shell
# You may be prompted to install `vite-bundle-visualizer`. Accept the prompt to install it.
npm run analyze:size
```

This will use [`vite-bundle-visualizer`][vite-bundle-visualizer] to generate an interactive visual
breakdown of bundle contents, helping identify large dependencies and optimization opportunities.

## Future strategies

The following optimization strategies are planned for the future:

* **Code splitting**: We can split the code into smaller chunks to improve load time, especially
when using lazy loading.
* **Lazy loading**: We can load components or modules only when they are needed. This can be
achieved by using dynamic imports or React's `lazy()` and `Suspense` features.

Comment on lines +21 to +25
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Optional: Enrich future strategies with Vite specifics
Consider linking to your vite.config.ts for manual chunking examples (e.g. Monaco editor) or mentioning npm run preview for production build previews.

🤖 Prompt for AI Agents
In docs/src/dev-guide/optimization-guide.md around lines 21 to 25, enhance the
optimization strategies by adding Vite-specific details. Include a reference or
link to the vite.config.ts file to show examples of manual chunking, such as for
the Monaco editor, and mention the use of `npm run preview` to preview the
production build. This will provide practical guidance on applying these
strategies with Vite.

[vite-bundle-visualizer]: https://www.npmjs.com/package/vite-bundle-visualizer
32 changes: 23 additions & 9 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import CommonConfig from "eslint-config-yscope/CommonConfig.mjs";
import JestConfig from "eslint-config-yscope/JestConfig.mjs";
import ReactConfigArray from "eslint-config-yscope/ReactConfigArray.mjs";
import StylisticConfigArray from "eslint-config-yscope/StylisticConfigArray.mjs";
import TsConfigArray from "eslint-config-yscope/TsConfigArray.mjs";
import Globals from "globals";
import TsConfigArray, {createTsConfigOverride} from "eslint-config-yscope/TsConfigArray.mjs";


const EslintConfig = [
Expand All @@ -14,7 +13,24 @@ const EslintConfig = [
],
},
CommonConfig,

...TsConfigArray,
createTsConfigOverride(
[
"src/**/*.ts",
"src/**/*.tsx",
"test/**/*.ts",
],
"tsconfig.app.json"
),
createTsConfigOverride(
[
"jest.config.ts",
"vite.config.ts",
],
"tsconfig.node.json"
),

...StylisticConfigArray,
...ReactConfigArray,
{
Expand All @@ -41,13 +57,11 @@ const EslintConfig = [
},
],
},
},
{
files: ["webpack.*.js"],
languageOptions: {
globals: {
...Globals.node,
},
settings: {
// Rule "import/default" complains on Vite's web worker import directives.
"import/ignore": [
"\\.worker",
],
},
},
{
Expand Down
8 changes: 5 additions & 3 deletions public/index.html → index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<title>Log Viewer</title>
<meta charset="utf-8">
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="description" content="YScope Log Viewer">
<meta name="keywords"
content="yscope clp debug debugging large log logs s3 scanner viewer vscode">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, width=device-width" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" crossorigin href="https://fonts.gstatic.com">
<link rel="stylesheet"
Expand All @@ -16,5 +17,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os from "node:os";
import pathPosix from "node:path/posix";
import * as os from "node:os";
import * as pathPosix from "node:path/posix";

import type {Config} from "jest";

Expand Down
Loading