-
-
Notifications
You must be signed in to change notification settings - Fork 655
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
Improve WebView build system #2690
Conversation
a7e74f0
to
a4e966b
Compare
Excellent, thanks @borisyankov ! It'll be great to have this system cleaned up -- I'm already appreciating how it makes the IDE able to highlight and show warnings in A few things I'd like to see changed before merging this:
|
9043de7
to
b362ea1
Compare
26e27b4
to
8d2e219
Compare
I did undo the removal of the
|
About the duplication of files. I researched today, and while Android is reasonably straight-forward, not so with iOS. I will continue exploring a solution for both platforms but suggest we do work on merging this first? |
Ah, OK, thanks. Would you add something in the repo explaining how to do that regeneration? A little script in The rest of that example still applies -- I'd be much happier seeing a commit that added Similarly, I'd like to have one commit (a) add I think a good commit, or series of commits, to start with would be to just switch from
Sure; I'd be OK with merging for now a version with the duplicate files. We can focus first on the other aspects discussed above. |
8a53bf9
to
9945dc0
Compare
Add a constant `baseUrl` that is platofrm-dependent and points to the URL of the local resource directory on the device. On iOS it is just a relative path `./`. On Android it points to the asset directory `file:///android_asset/`. We also add a subfolder `webview` to keep stuff organized.
Function is given a resource file name and returns the URL to be used by WebView to refer to a resource on that device.
Instead of importing these as string files during build time, we will refer to the files as resources during runtime. * add the `Element.matches` polyfill * add the unminified version of `smooth-scroll`
* 'theme.css' are all the normal styles * 'dark.css' are the dark-theme styles
Instead of generating the data dynamically (in cssEmojis.js) just store it in `emoji.css`. This makes the dynamically generated parts much shorter and easier to debug. We keep the `cssEmoji.js` file intact, as we can use it to generate the `emoji.css` file again if input data changes.
Instead of just compiling the js file, now we do that but also copy the files in `src/webview/assets/` to be imported from the webview directly. Now the compiled JS file is not a string that gets imported but is a normal JS file. The command to be run now is `yarn build-webview` - to better reflect the process.
This is the result of running `yarn build-webview` The files need to be copied twice for the two platforms.
The process for Android is automatic and nothing special is needed. For iOS this is done from within XCode: * open the project * open Project Navigator * right click on ZulipMobile * select 'Add Files to "ZulipMobile"...' * add the `ios/webview` folder When adding more assets in the future we'll need to repeat the process but only for the new files.
Providing a `baseUrl` relative to device's assets location allows us to load external resources. Initially we set `baseUrl` to realm's root so relative URLs point correctly. We did not need that though, as currently all URLs are either absolute or we transform them to absolute.
Delete the imported-string-from-js code used before and load css styles from device's local assets.
Instead of loading imported-strings-as-js we just refer to the asset files of the device. Also, move the `scripts` code to the bottom of the page. This was initially moved to the top so the reported error code-lines are more predictable (the different html was messing up the count). Now we don't need that, so simplify.
This is the full `pygments.scss` file complied. Also add the `code.css` file via XCode.
Removes the very small subset of code-highlighting styles from `css.js` (manually added when we used native-rendering) and use the full pygments `code.css` file as resource.
Makes dark theme styling consistent with how this is done in the web app. Instead of conditionally including `dark.css` do include it always, but make the styles apply only when `body` has a class of `night-mode`. This makes the `code.css` file, already having styles in this format work well in night mode.
This is consistent with how the web app styles the code blocks. `.codehilite` has a background by default. Overwrite the style instead of changing the styles in `code.css` keep the file unchanges (directly coming from 'pygments') for easier update later.
This is the main `katex.less` file compiled to css https://github.com/Khan/KaTeX/blob/master/src/katex.less We do not yet include the custom fonts, but still the improvement in rendering LaTeX is significant.
Remove the `generatedEs3.js` file and add the two asset folders.
Use `yarn build-webview -w` or `yarn build-webview --watch` The input files are watched for changes. If asset files change, they are copied again to the asset folders. If the JavaScript file changes, it is recompiled.
9945dc0
to
3ebe60e
Compare
Heads up @borisyankov, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the |
Bumping the priority because this blocks #2660, which people keep asking for and I just bumped. |
At present, when loading content into the WebView, we inject all non-image assets as part of the generated HTML. This is more than a bit wasteful, considering that large swaths of the supporting CSS and JavaScript is entirely static from invocation to invocation; additionally, it makes KaTeX support somewhere between "nontrivial" and "impossible". This commit creates a build subsystem which can inject static webview-supporting assets into the application bundle, into a `webview` directory. We also create a stub directory for the subsystem copy assets from; at present this contains only a README.md file (which will *not* be copied), but this will be expanded in the following series of commits. Inspired by zulip#2690. Assists with zulip#2660, zulip#3595, and potentially many other issues.
At present, when loading content into the WebView, we inject all non-image assets as part of the generated HTML. This is more than a bit wasteful, considering that large swaths of the supporting CSS and JavaScript is entirely static from invocation to invocation; additionally, it makes KaTeX support somewhere between "nontrivial" and "impossible". This commit creates a build subsystem which can inject static webview-supporting assets into the application bundle, into a `webview` directory. We also create a stub directory for the subsystem to copy assets from; at present this contains only a README.md file (which will *not* be copied), but this will be expanded in the following series of commits. Inspired by zulip#2690. Assists with zulip#2660, zulip#3595, and potentially many other issues.
At present, when loading content into the WebView, we inject all non-image assets as part of the generated HTML. This is more than a bit wasteful, considering that large swaths of the supporting CSS and JavaScript is entirely static from invocation to invocation; additionally, it makes KaTeX support somewhere between "nontrivial" and "impossible". This commit creates a build subsystem which can inject static webview-supporting assets into the application bundle, into a `webview` directory. We also create a stub directory for the subsystem to copy assets from; at present this contains only a README.md file (which will *not* be copied), but this will be expanded in the following series of commits. Inspired by zulip#2690. Assists with zulip#2660, zulip#3595, and potentially many other issues.
At present, when loading content into the WebView, we inject all non-image assets as part of the generated HTML. This is more than a bit wasteful, considering that large swaths of the supporting CSS and JavaScript is entirely static from invocation to invocation; additionally, it makes KaTeX support somewhere between "nontrivial" and "impossible". This commit creates a build subsystem which can inject static webview-supporting assets into the application bundle, into a `webview` directory. We also create a stub directory for the subsystem to copy assets from; at present this contains only a README.md file (which will *not* be copied), but this will be expanded in the following series of commits. Inspired by zulip#2690. Assists with zulip#2660, zulip#3595, and potentially many other issues.
At present, when loading content into the WebView, we inject all non-image assets as part of the generated HTML. This is more than a bit wasteful, considering that large swaths of the supporting CSS and JavaScript is entirely static from invocation to invocation; additionally, it makes KaTeX support somewhere between "nontrivial" and "impossible". This commit creates a build subsystem which can inject static webview-supporting assets into the application bundle, into a `webview` directory. We also create a stub directory for the subsystem to copy assets from; at present this contains only a README.md file (which will *not* be copied), but this will be expanded in the following series of commits. Inspired by #2690. Assists with #2660, #3595, and potentially many other issues.
This is an important rework of how building the WebView assets work.
Considered 'merge-ready', it is the base for further improvements.
This rework now enables the
WebView
to load its assets (styles, js, potentially fonts) from external files and not need to be built into the singleJS
file.This approach is needed so we can embed:
Makes it simpler to embed:
In addition, this makes the reported error line-numbers in JS reliable.
This also adds: