-
Notifications
You must be signed in to change notification settings - Fork 549
Web Portal: Optimize speed of npm start
#1021
Conversation
Docs will be updated after #1000 merged |
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.
"test": "npm run lint", | ||
"webpack": "webpack --config webpack.config.js --progress --profile", | ||
"clean": "rimraf dist", | ||
"prebuild": "npm run clean && node config/preprocess.js", |
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.
When are prebuild
and prestart
called?
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.
@hwuu They run automatically just before build
& start
@@ -114,6 +114,6 @@ | |||
<div class="control-sidebar-bg"></div> | |||
|
|||
</div> | |||
|
|||
<script src="scripts/env.js"></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.
Why do you add this to this .ejs file? I'm wondering whether 'require' the .js file in job-view.component.js is sufficient?
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.
@hwuu layout.component.ejs
is the base template of all html pages, it makes all page scripts can access window.ENV
by require('webportal.config.js')
@@ -0,0 +1,10 @@ | |||
/* eslint-disable */ | |||
window.ENV = { |
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'm curious about how your method works. I guess this env.js is a template, and it will be dynamically instantiated by envsub inside the container before the service starts (the 'prestart' command of npm). Am I right?
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.
@hwuu You are right, this makes the environment variables injected to window.ENV in the runtime, not related to webpack build.
@@ -19,7 +19,7 @@ | |||
|
|||
const hardwareDetailComponent = require('./hardware-detail.component.ejs'); | |||
const breadcrumbComponent = require('../../job/breadcrumb/breadcrumb.component.ejs'); | |||
const webportalConfig = require('../../config/webportal.config.json'); | |||
const webportalConfig = require('../../config/webportal.config.js'); |
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.
Is it a common practice that we'd better 'require' a .js file other than a .json file?
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.
@hwuu In fact require('webportal.config')
is better, it will make webpack to choose the most suitable extension, even .ts
if exists and related plugin is used.
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 your clarification. All clear. Approved.
Benchmarks:
Build:
Run:
|
1. Move `npm run build` run in image build stage, decouple with env. 2. Inject env to `window.ENV` in `env.js`, refernced by all pages. 3. Rename `webportal.config.json` to js, which exports `window.ENV`.
5016861
to
2bee67c
Compare
2bee67c
to
90b380e
Compare
webportal/package.json
Outdated
@@ -74,7 +74,7 @@ | |||
"prebuild": "npm run clean && node config/preprocess.js", | |||
"build": "webpack --config webpack.config.js --progress --profile", | |||
"build:dev": "npm run build -- --debug --devtool eval-cheap-module-source-map --output-pathinfo --watch", | |||
"prestart": "envsub --env-file .env --system src/app/env.js dist/scripts/env.js", | |||
"prestart": "envsub --env-file .env --system src/app/env.js dist/scripts/env.js && ping -c 1 -W 1 172.17.0.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.
Explain a little?
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's a workaround to pass the cluster deploy test in Jenkins, not related to this optimization. I will revert it and raise a new PR to discuss it.
This reverts commit 90b380e.
npm run build
run in image build stage, decouple with env.window.ENV
inenv.js
, refernced by all pages.webportal.config.json
to js, which exportswindow.ENV
.Closes #936