-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
[DEV] Allow webpack-dev-server proxy to any destination #9296
Conversation
// make sure the manifest file exists | ||
fs.mkdirSync(path.dirname(MANIFEST_FILE), { recursive: true }); | ||
fs.closeSync(fs.openSync(MANIFEST_FILE, 'as+')); | ||
fs.watch(MANIFEST_FILE, loadManifest); |
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.
Reload manifest every time there is a new build.
{% macro js_bundle(filename) %} | ||
{# HTML comment is needed for webpack-dev-server to replace assets | ||
with development version #} | ||
<!-- Bundle js {{ filename }} START --> |
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.
The downside is this adds such HTML comments even to the production mode. Can probably create a config flag DISABLE_ASSET_BUNDLE_WATERMARK
to turn this off.
2a299d8
to
c993eac
Compare
@@ -236,7 +236,8 @@ | |||
"webpack-bundle-analyzer": "^3.4.1", | |||
"webpack-cli": "^3.1.1", | |||
"webpack-dev-server": "^3.1.14", | |||
"webpack-sources": "^1.1.0" | |||
"webpack-sources": "^1.1.0", | |||
"yargs": "12 - 15" |
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.
Replace minimist
with yargs
as the latter has better API and is included by other packages anyway. Choose this wide range (12 -15
) also because it is tested working with the latest version but other packages still depend on v12.
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.
What other packages are depending on it? Do we have any script that depends on it?
Could we try to get this to 15
?
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.
jest-cli
and webpack-dev-server
uses 12
, vega-lite
uses 15
. 15
is the latest version, the latest webpack-dev-server
hasn't upgraded it yet.
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.
Wow, just found out there is a bot that automatically upgrade the packages for you, plus migrating all the code. Maybe we can use it to replace dependabot in superset-ui
and superset-ui-plugins
.
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.
jest-cli and webpack-dev-server uses 12, vega-lite uses 15. 15 is the latest version, the latest webpack-dev-server hasn't upgraded it yet.
Do those list yargs
as peerDependencies
or dependencies
? npm
allow nested dependencies so it may install multiple versions of yargs
, which is inefficient to have multiple copies, but not too bad. IMO, it might be good to be specific for the script stability.
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.
Renovate looks interesting.
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.
They list it as dependencies
. The range is specifically to avoid multiple copies. I think it's OK to keep this range for now as we didn't use it too extensively and we already know both v12 and v15 works for our code.
() => { | ||
return proxyConfig; | ||
}, | ||
], |
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.
Hot reload borrowed from here.
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.
Overall, awesome work! This should make testing with production data much easier!
Will be good to have another python-eye to check the python code.
@@ -236,7 +236,8 @@ | |||
"webpack-bundle-analyzer": "^3.4.1", | |||
"webpack-cli": "^3.1.1", | |||
"webpack-dev-server": "^3.1.14", | |||
"webpack-sources": "^1.1.0" | |||
"webpack-sources": "^1.1.0", | |||
"yargs": "12 - 15" |
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.
What other packages are depending on it? Do we have any script that depends on it?
Could we try to get this to 15
?
} | ||
|
||
function toDevHTML(origHtml) { | ||
let html = origHtml.replace( |
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 move this block of code below the
loadManifest()
block. - can use full word for clarity
origHtml
=>originalHtml
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 think origHtml
is more in line with origRes
used elsewhere in this file, otherwise should I rename origRes
to originalResponse
, henceforth res
to response
, and req
to request
as well?
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.
That would be nice.
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.
Updated the variable names!
Codecov Report
@@ Coverage Diff @@
## master #9296 +/- ##
=======================================
Coverage 59.08% 59.08%
=======================================
Files 374 374
Lines 12202 12202
Branches 2986 2986
=======================================
Hits 7209 7209
Misses 4814 4814
Partials 179 179 Continue to review 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.
Thanks for addressing the comments. Just a few minor
@@ -236,7 +236,8 @@ | |||
"webpack-bundle-analyzer": "^3.4.1", | |||
"webpack-cli": "^3.1.1", | |||
"webpack-dev-server": "^3.1.14", | |||
"webpack-sources": "^1.1.0" | |||
"webpack-sources": "^1.1.0", | |||
"yargs": "12 - 15" |
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.
jest-cli and webpack-dev-server uses 12, vega-lite uses 15. 15 is the latest version, the latest webpack-dev-server hasn't upgraded it yet.
Do those list yargs
as peerDependencies
or dependencies
? npm
allow nested dependencies so it may install multiple versions of yargs
, which is inefficient to have multiple copies, but not too bad. IMO, it might be good to be specific for the script stability.
} | ||
|
||
function toDevHTML(origHtml) { | ||
let html = origHtml.replace( |
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.
That would be nice.
@@ -236,7 +236,8 @@ | |||
"webpack-bundle-analyzer": "^3.4.1", | |||
"webpack-cli": "^3.1.1", | |||
"webpack-dev-server": "^3.1.14", | |||
"webpack-sources": "^1.1.0" | |||
"webpack-sources": "^1.1.0", | |||
"yargs": "12 - 15" |
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.
Renovate looks interesting.
One of the pain points in developing Superset frontend code is the lack of testing data. Local installation often do not have enough examples setup to test all edge cases. This change allows `webpack-dev-server` to proxy to any remote Superset service, but the same time replaces frontend asset references in HTML with links to local development version. This allows developers to test with production data locally, tackling edge cases all while maintaining the productivity of editing the code locally.
Tested again with a fresh installation. Didn't see any issues. I think this is ready to merge. |
CATEGORY
SUMMARY
One of the main pain points in developing Superset frontend features is the lack of testing data. Local installations often do not have enough examples conveniently set up to test different edge cases. Because of the multi-repo workflow with chart plugins, it also get complicated to set up an editable frontend building environment on remote servers.
This PR allows
webpack-dev-server
to proxy to any remote Superset web service, but at the same time replaces CSS/JS asset references in the response HTML with locally built chunk files that have source map and hot reload support. The remote Superset service must be running on a version later than this PR.This allows developers to start the frontend server locally, but test with production/staging data served by a remote server. This setup makes it easier to debug edge cases all while maintaining the productivity of writing code in a local IDE.
The only caveat is that this solution may not work for some complex user authentication configurations that require OAuth callbacks or cross-domain redirects.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TEST PLAN
Using following command to proxy dev-server to a remote Superset service:
Or use a local reverse proxy or SSH port forwarding to forward remote service to
http://localhost:8088
.The page should load normally with locally built assets and JS hot reloading should work.
ADDITIONAL INFORMATION
N/A
REVIEWERS
cc @kristw @etr2460 @rusackas @john-bodley