-
Notifications
You must be signed in to change notification settings - Fork 406
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
Introduce salesforcedx-webview-ui package #451
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #451 +/- ##
===========================================
- Coverage 76.38% 75.88% -0.51%
===========================================
Files 138 139 +1
Lines 5400 5436 +36
Branches 845 851 +6
===========================================
Hits 4125 4125
- Misses 1066 1102 +36
Partials 209 209
Continue to review full report at Codecov.
|
@@ -0,0 +1,122 @@ | |||
# Introduction |
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 the main file that you should read to get the gist of this PR.
The other parts I will illustrate to the team via an internal demo.
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.
@lcampos - Would appreciate your thoughts on this.
We can still merge this in and we can continue the discussion later but it would be appreciated if you could share some thoughts on this based on your work with sutro - I'm not sure if you were using webviews there (or browserview).
Either way, the links in the README.md should be useful.
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 did look at using webviews but I was able to make it work by using TextDocumentContentProvider to render my html/js. I didn't need to modify anything outside of the html/js files I was rendering.
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.
Ok, seems WebViews is the "new" way to go based on this https://code.visualstudio.com/updates/v1_21#_webview-api
446a2b0
to
c9689fe
Compare
|
||
* [`<webview>` Tag](https://electronjs.org/docs/api/webview-tag) | ||
* [Interop’s Labyrinth: Sharing Code Between Web & Electron Apps](https://slack.engineering/interops-labyrinth-sharing-code-between-web-electron-apps-f9474d62eccc) | ||
* [Growing Pains: Migrating Slack’s Desktop App to BrowserView](https://slack.engineering/growing-pains-migrating-slacks-desktop-app-to-browserview-2759690d9c7b) |
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.
There are some bugs with webview in Electron. See https://github.com/electron/electron/issues?q=is%3Aopen+is%3Aissue+label%3Acomponent%2Fwebview
However, I searched on the VS Code repo and there were no discussions about considering using BrowserView
instead of WebView
. So that option doesn't seem to exist for VS Code.
|
||
# Developer Flow | ||
|
||
## Rapid Iteration of the UI |
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 currently just showing me a blank page, is it expected ? I do see the manifest editor when I run the extensions tho.
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.
Did you navigate to http://localhost:3000/ManifestEditor
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 was it, thanks
// Also exclude `html` and `json` extensions so they get processed | ||
// by webpacks internal loaders. | ||
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/], | ||
loader: require.resolve('file-loader'), |
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.
Did you try something like
{ test: /.(jpe?g|png|gif|svg|woff|eot|ttf)$/i, loader: 'file-loader?name=/media/[name].[ext]' }
? I have it working like that in another project but it might be because I'm on a more recent version of file-loader.
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.
Will try. I wasn't sure if you could pack svg|woff|eot|ttf. That would help.
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 might be misunderstanding here but this should be OK because this is the last branch of the oneOf branch. That means we shouldn't need to add more tests. In fact, this test is the not
of the other branches.
So, we are already serving the svg, woff, eot, and ttf files. For jpeg, png, gif we actually convert embed them as data URLS to avoid any requests. See
salesforcedx-vscode/packages/salesforcedx-webview-ui/config/webpack.config.dev.js
Line 121 in e84a517
// "url" loader works like "file" loader except that it embeds assets |
What I've done is also add woff|eot|ttf so that they get embedded.
I verified that we must be serving them properly because blueprint.js uses some custom font for the icons and we are seeing those icons in the manifest editor.
"engines": { | ||
"vscode": "^1.17.0" | ||
}, | ||
"dependencies": { |
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.
Everything webpack, loaders, jest etc should be under devDependencies.
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.
Interesting. I got this from create-react-app. This was the section that they put it in. I can move them into dev-dependencies.
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 guess it depends on how we are bundling the extension, are we keeping them as part of node_modules when creating the extension?
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.
Nope, we only bundle the stuff that is optimized in the /build folder. So nothing from node_modules leaks in. Everything has to be bundled in a way that you can just load the .html/.js/etc. All the JS is bundled as UMD, not That's why I think it's OK and that is why create-react-app did it that way. I will investigate more but I don't think I change this from how they were doing it.
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 looking at https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/package.json and https://github.com/wmonk/create-react-app-typescript/blob/master/packages/react-scripts/package.json
It seems that react, react-dom, and typescript are in the devDependencies. Let me move those back in there to follow that (not sure how it got moved into dependencies).
I will keep webpack and rest in dependencies for now since that seems to be how the template it.
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.
More info at facebook/create-react-app#1764
"tslint-react": "3.2.0", | ||
"uglifyjs-webpack-plugin": "1.1.8", | ||
"url-loader": "0.6.2", | ||
"webpack": "3.8.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.
😍
@@ -0,0 +1,6 @@ | |||
import * as React from 'react'; | |||
import * as ReactDOM from 'react-dom'; |
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.
We should change this to import { render } from 'react-dom'; so it will only import the render method and nothing else.
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.
Doesn't the tree shaking and dead-code elimination from webpack solve the issue of bringing too much? Or am I overestimating what it can do?
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.
Tree shaking will remove that, but I didn't see anything for that on the webpack config files. Is babel compiling to ES6? If it is then webpack will automatically do tree shaking.
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.
salesforcedx-vscode/packages/salesforcedx-webview-ui/config/webpack.config.prod.js
Line 284 in e84a517
ecma: 5, |
Looks like we are still compressing/outputting to ecma5. Let me get it into ecma 6. We should use es6 to be consistent with the rest of the output from vs code.
I see now that tree shaking is only enabled for es6 or es2015. https://webpack.js.org/guides/tree-shaking/
This is the package that will contain all the .html that we will use for each webview. @W-5013822@
Nothing fancy but it showcases the behavior and ability.
Since this is tied to the salesforcedx-vscode-core extension that only loads when a sfdx-project.json is around.
db9c92e
to
23bf1c2
Compare
@lcampos - The current version of create-react-app uses webpack 3.8.1 and not webpack 4 yet. We can decide to update this later if needed. I can't find an official upgrade doc like I could for webpack 2 -> 3 (https://webpack.js.org/migrate/3/) |
@vazexqi there's not migration guide yet but there's some progress being made and tracked here (webpack/webpack.js.org#1706). Right now, unless we see build/bundle perf issues I'd say we can wait to move to v4. |
What does this PR do?
This is the package that will contain all the .html that we will use for each webview. We will use this to create webviews that will be surfaced in VS Code. This will be based on the approach documented at https://code.visualstudio.com/docs/extensions/webview
What issues does this PR fix or reference?
@W-5013822@