-
Notifications
You must be signed in to change notification settings - Fork 497
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
Migrate build tooling to Vite #1226
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1226 +/- ##
==========================================
+ Coverage 95.40% 95.43% +0.03%
==========================================
Files 244 244
Lines 7589 7751 +162
Branches 1901 2017 +116
==========================================
+ Hits 7240 7397 +157
- Misses 349 353 +4
- Partials 0 1 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
|
||
// Workaround some legacy NPM dependencies that assume this is always defined. | ||
window.global = {}; | ||
// Avoid noise from redux-form until https://github.com/redux-form/redux-form/pull/4723 is released. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to file an issue in this repo to track this and explain what needs to be done once the redux issue is resolved.
To begin the development, run `npm start` in this folder. | ||
To create a production bundle, use `npm run build`. | ||
--> | ||
<script type="module" src="/src/index.tsx"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unexpected. Is the browser supposed to interpret a typescript file?
I also wonder about the /src/ prefix, how that would work with jaeger-query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It gets replaced with a proper asset at build time (https://vitejs.dev/guide/features.html#typescript).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please compare the size of the overall ui-asset bundle after switching to Vite? Add it to the PR description as a benchmarking data point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the last CI build from main
, the results from CRA are:
File sizes after gzip:
863.25 KB build/static/js/1.2bd86f79.chunk.js
654.32 KB build/static/js/main.c8c51bfd.chunk.js
43.11 KB build/static/css/1.7f7667b5.chunk.css
10.62 KB build/static/css/main.5918f9f5.chunk.css
763 B build/static/js/runtime~main.4a686d48.js
That'd be ~1519 kB of JS (gzipped) and ~54 kB of CSS (gzipped).
For this branch, we have:
build/index.html 5.17 kB
build/static/monitor-9000dba4.png 111.77 kB
build/static/jaeger-logo-ab11f618.svg 161.92 kB
build/static/index-b15a508e.css 352.14 kB │ gzip: 56.11 kB
build/static/index-1af2a95e.js 6,008.36 kB │ gzip: 1,642.99 kB
So the JS bundle ends up larger. Not immediately sure what the increase is due to; will add rollup-plugin-visualizer
locally to try and hopefully determine that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One finding: the old build system used babel-plugin-import
not just for the antd
handling but also for magically optimizing lodash
imports. Most places already use lodash/subComponent
import style to only import needed code, but some import the entire library. Locally, changing those to all use appropriate subcomponent imports shaved off ~30 kB from the gzipped bundle.
With that, the bundle ends up like this:
It seems the biggest opportunity for saving some bytes would be to lazy-load dependencies that are only needed on specific pages, e.g. plexus
, or the pyroscope flamegraph visualizer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, lazy loading those would be good. Does it require changing the build to produce several js files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is doable by using dynamic imports for the chunks that we want to lazyload. I tested locally with DAG.jsx
by moving the top-level imports for cytoscape
and related deps into the componentDidMount
callback:
const [{ default: cytoscape }, { default: cydagre }, { default: dagre }] = await Promise.all([
import('cytoscape'),
import('cytoscape-dagre'),
import('dagre'),
]);
This split out these dependencies from the main chunk and Vite automatically generated separate chunks for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the issue with lodash
, we could make a separate PR to convert the few usages where the entirety of lodash
is imported into appropriate sub-component imports. Alternatively, it could also be solved by switching it out for lodash-es
, which is lodash
but built as ES modules, making import { foo } from 'lodash-es'
"just work" without requiring a special plugin (it'd only import foo
and not the whole library).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1,59 +0,0 @@ | |||
// Copyright (c) 2019 Uber Technologies, Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we need it? IIRC the proxy was used to allow running dev version of the UI on port 3000 while running all-in-one on the official port
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proxying is now configured in vite.config.ts
, so this file can go away.
@@ -12,7 +12,7 @@ | |||
// See the License for the specific language governing permissions and | |||
// limitations under the License. | |||
|
|||
// This file is necessary because create-react-app (CRA) requires | |||
// This file is necessary because the build system (Vite) requires | |||
// isolatedModules to be true but for linting we need it to be false. We run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious if the new build would help remove the need for this override / split.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it out, but unfortunately got some failures (Vite and most build tools imply isolatedModules
), so I decided to not extend the scope of this PR with potential TS changes. But yeah, it's something worth checking separately.
@@ -1,24 +0,0 @@ | |||
@primary-color: #199; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to packages/jaeger-ui/vite.config.ts
@@ -1,3 +0,0 @@ | |||
module.exports = async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to packages/jaeger-ui/test/jest.global-setup.js
260d9fb
to
f2921bc
Compare
Switch the project to build using Vite, per the considerations outlined in jaegertracing#1212. Notable changes are: * `react-scripts` would provide some built-in Jest transforms and mocks under the hood, which need to be defined explicitly now. * Build-time injected constants no longer utilize `process.env`. Signed-off-by: Máté Szabó <[email protected]>
f2921bc
to
426f021
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great! I will do some manual testing over the weekend.
Signed-off-by: Yuri Shkuro <[email protected]>
🥳 🥳 🥳 |
## Which problem is this PR solving? - Contributes towards jaegertracing#818, jaegertracing#1199 ## Short description of the changes Switch the project to build using Vite, per the considerations outlined in jaegertracing#1212. Notable changes are: * `react-scripts` would provide some built-in Jest transforms and mocks under the hood, which need to be defined explicitly now. * Build-time injected constants no longer utilize `process.env`. ## Testing For this, I spun up a local `all-in-one` jaeger instance and fed it some test data with `microsim`. I updated the `jaeger-ui` submodule reference for this local jaeger checkout to point to this branch to test the behavior of the production build. I then navigated around looking for errors on the pages or the console. <img width="1512" alt="Screenshot 2023-03-02 at 01 07 39" src="https://user-images.githubusercontent.com/2721291/222296252-539ac6e0-15b5-49d6-943c-e437b852704e.png"> --------- Signed-off-by: Máté Szabó <[email protected]> Signed-off-by: Yuri Shkuro <[email protected]> Co-authored-by: Yuri Shkuro <[email protected]>
"@svgr/babel-plugin-transform-svg-component": "^6.5.1", | ||
"@svgr/babel-preset": "^6.5.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ mszabo-wikia do you know why/if these were needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is likely an artifact. I thought it was still being used by tests for SVG support, but it seems those use babel-plugin-inline-react-svg
instead (test/babel-transform.js). So these are probably OK to remove assuming that tests pass without them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, appreciate your comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for reaching out! :)
Related to: #1675 and #1672 <!-- !! Please DELETE this comment before posting. We appreciate your contribution to the Jaeger project! 👋🎉 --> ## What changes is this PR making? - This PR removes the unused packages from packages/jaeger-ui - The removed packages are: - `@svgr/babel-plugin-transform-svg-component` - `@svgr/babel-preset` - `@types/react-dom` - `@types/react-router-redux` ## Description of the changes - As per the discussion #1226 (comment), and the manual check. Previously, I was reluctant in removing `@types/react-dom` and `@types/react-router-redux` because their corresponding packages are used, but I gave them a test by removing: - run `yarn lint` - no errors - remove these two packages and again run `yarn lint` - no errors - maybe linter is not working correctly, so removed `@types/react-window` - run `yarn lint` - type errors - added back `@types/react-window` and run `yarn lint` - no errors - Thus, these two deps aren't needed ## How was this change tested? - By running yarn lint and yarn test ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: Ansh Goyal <[email protected]>
Related to: jaegertracing#1675 and jaegertracing#1672 <!-- !! Please DELETE this comment before posting. We appreciate your contribution to the Jaeger project! 👋🎉 --> ## What changes is this PR making? - This PR removes the unused packages from packages/jaeger-ui - The removed packages are: - `@svgr/babel-plugin-transform-svg-component` - `@svgr/babel-preset` - `@types/react-dom` - `@types/react-router-redux` ## Description of the changes - As per the discussion jaegertracing#1226 (comment), and the manual check. Previously, I was reluctant in removing `@types/react-dom` and `@types/react-router-redux` because their corresponding packages are used, but I gave them a test by removing: - run `yarn lint` - no errors - remove these two packages and again run `yarn lint` - no errors - maybe linter is not working correctly, so removed `@types/react-window` - run `yarn lint` - type errors - added back `@types/react-window` and run `yarn lint` - no errors - Thus, these two deps aren't needed ## How was this change tested? - By running yarn lint and yarn test ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: Ansh Goyal <[email protected]>
Which problem is this PR solving?
Short description of the changes
Switch the project to build using Vite, per the considerations outlined in #1212.
Notable changes are:
react-scripts
would provide some built-in Jest transforms and mocks under the hood, which need to be defined explicitly now.process.env
.Testing
For this, I spun up a local
all-in-one
jaeger instance and fed it some test data withmicrosim
. I updated thejaeger-ui
submodule reference for this local jaeger checkout to point to this branch to test the behavior of the production build. I then navigated around looking for errors on the pages or the console.