Skip to content
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

JavaScript libraries bundling #12172

Closed
11 tasks done
nijel opened this issue Aug 1, 2024 · 8 comments · Fixed by #13093
Closed
11 tasks done

JavaScript libraries bundling #12172

nijel opened this issue Aug 1, 2024 · 8 comments · Fixed by #13093
Assignees
Labels
enhancement Adding or requesting a new feature.
Milestone

Comments

@nijel
Copy link
Member

nijel commented Aug 1, 2024

Describe the problem

Right now, Weblate uses custom tooling to include vendored libraries (see https://docs.weblate.org/en/latest/contributing/frontend.html#dependency-management). This is tricky to deal with for new contributors and brings issues when updating some libraries (see for example https://github.com/WeblateOrg/weblate/actions/runs/10178733602/job/28152952153?pr=11956 in #11956).

Describe the solution you would like

There should be some standard solution that works for us. Requirements (those can be discussed, though):

  • No additional runtime or installation time requirements besides Python modules.
  • Store only needed files in Git, not full vendored packages.

Describe alternatives you have considered

Things like webpack could be a solution. It might also replace the currently used django-compressor.

Screenshots

No response

Additional context

List of libraries to migrate:

  • @tarekraafat/autocomplete.js
  • autosize
  • daterangepicker
  • mousetrap
  • mousetrap-global-bind
  • multi.js
  • prismjs
  • slugify
  • source-code-pro
  • source-sans
  • tributejs

Libraries which probably won't be migrated:

  • bootstrap-rtl as we use a newer snapshot than the release available as a package
  • boostrap is using customized build

Maybe we should focus on #2916 instead.

@meel-hd
Copy link
Contributor

meel-hd commented Aug 5, 2024

@nijel This will be a big improvement.

To sum up, currently used 3d party code is included in the app by weblate/templates/base.html by more than a dozen script tags. linking to large 3rd party library files. Which are installed by yarn and copied using custom tooling into static/vendor.

So given the desired results here it is what we will have:

  • Ease of install and update (one command yarn install library).
  • Familiar to new contributors (The same usual workflow used by the web dev community using npm/yarn, with no need for custom tooling.)
  • Installs will be stored in the gitignored folder node_modules.
  • The use of the 3rd party code in static/vendor will be unnecessary and can be removed.
  • There will be one source of truth for declaring the use of third party code.

How:
1- We will introduce a new directory vendor/ for managing frontend 3rd party code.
2- It will contain the index.js, package.json, yarn.lock, webpack.config.js and the gitignored node_modules/.
3- index.js Will be used to import the libraries necessary for the frontend. And remove them if needed too.
4- Webpack will be used to build and bundle the libraries used and declared in index.js into a minified file.
5- The resulted .js file will be included into the base.html template. To make it available for the parts that needs it.

**Visual Representation: **
image

Some questions:

  • What bundler we should use (the most well known ones are webpack, vite, parcel, and rollup).
  • I am not sure if we should git track the output .min.js file.
  • How to integrate this in the Docker workflow.
  • Adaption of this will be on one time or gradual.
  • And at last. did I miss something or there is some possible better solutions?

@nijel
Copy link
Member Author

nijel commented Aug 5, 2024

1- We will introduce a new directory vendor/ for managing frontend 3rd party code.

How about placing it under client to make it clear this is client-side code?

* What bundler we should use (the most well known ones are webpack, vite, parcel, and rollup).

Recommendations are welcome.

* I am not sure if we should git track the output `.min.js` file.

Probably yes, so that install from Git works without building the js files.

* How to integrate this in  the Docker workflow.

This is another reason to have .min.js files in the Git, the snapshot containers are installed using that.

* Adaption of this will be on one time or gradual.

I'd start with the migration of a few libraries as a proof of concept. How about starting with Sentry (which needs building anyway) and fonts (to make sure that assets are handled correctly).

* And at last. did I miss something or there is some possible better solutions?

@meel-hd
Copy link
Contributor

meel-hd commented Aug 5, 2024

Uh true the name client is better.

For the bundler I would recommend Vite since we are going to track the output file with git. It produces Smaller bundles in comparison to the others. Also it is known for its speed which makes the developer experience better. Moreover it supports Hot module reloading if we add rebuilds on changes for the frontend in the future, it will be already available.

Other things I think are great I will continue with it from here. I will implement this starting with sentry.

Copy link

This issue has been automatically marked as stale because there wasn’t any recent activity.

It will be closed soon if no further action occurs.

Thank you for your contributions!

@github-actions github-actions bot added the wontfix Nobody will work on this. label Aug 20, 2024
@nijel nijel added enhancement Adding or requesting a new feature. and removed wontfix Nobody will work on this. labels Aug 20, 2024
@nijel nijel added this to the 5.8 milestone Sep 20, 2024
@nijel nijel modified the milestones: 5.8, 5.9 Oct 9, 2024
nijel added a commit that referenced this issue Oct 9, 2024
This has been installed manually since ever, so remove it from deps.

See also #12172
@nijel
Copy link
Member Author

nijel commented Oct 9, 2024

@meel-hd I've added list of deps into initial comment, I think now it's time to address theme one by one.

@meel-hd
Copy link
Contributor

meel-hd commented Oct 10, 2024

@nijel in progress. #12731 continues with TributeJs

@meel-hd
Copy link
Contributor

meel-hd commented Oct 14, 2024

Since tribute.js has been moved to the new build workflow in #12731. Working on moving @tarekraafat/autocomplete.js

meel-hd added a commit to meel-hd/weblate that referenced this issue Nov 7, 2024
This commit includes:
- Removed the libs from the old scripts/yarn workflow
- Removed js.cookie.js.license file.
- Removed the old scripts of moment and daterangepicker from base.html
- And they are now included automatically by main.js

Related: WeblateOrg#12172
nijel pushed a commit that referenced this issue Nov 7, 2024
This commit includes:
- Removed the libs from the old scripts/yarn workflow
- Removed js.cookie.js.license file.
- Removed the old scripts of moment and daterangepicker from base.html
- And they are now included automatically by main.js

Related: #12172
meel-hd added a commit to meel-hd/weblate that referenced this issue Nov 21, 2024
Changes Include:
- Removed the old scripts/yarn/** dir, as it is no longer needed.
- Moved source-code-pro and source-sans to client/
- Built and bundled the fonts.
- Updated templates to use the new built fonts and styles.
- Added new built bundles license info in REUSE.toml.

Note:
- The old bundles did not get removed to keep this PR simple for review.

TODO:
- Remove old fonts bundles.
- Update any dependents on them to use the new bundles.
- if FONTS_CDN_URL is configured it should be seted up with static/js/vendor/fonts instead of the old font-source/
- Remove the old yarn-update workflow and its configs and workflows

Related: WeblateOrg#12172
@nijel nijel linked a pull request Dec 7, 2024 that will close this issue
5 tasks
nijel added a commit that referenced this issue Dec 11, 2024
* Move source-code fonts to new build workflow

Changes Include:
- Removed the old scripts/yarn/** dir, as it is no longer needed.
- Moved source-code-pro and source-sans to client/
- Built and bundled the fonts.
- Updated templates to use the new built fonts and styles.
- Added new built bundles license info in REUSE.toml.

Note:
- The old bundles did not get removed to keep this PR simple for review.

Related: #12172

* Remove usage of fonts_cdn_url

* Delete scripts/yarn-update

* Remove old fonts and update dependents

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* use font names instead of hash

- Update docs/conf.py
- Update test_selenium.py

* Fix wrong merge

* Fix font extension

* Fix failed test on missing font

* Include TTF fonts needed for bitmap widgets

* Revert "Fix failed test on missing font"

This reverts commit 81d77ef.

* fix: correct fonts path

Co-authored-by: Michal Čihař <[email protected]>
Copy link

Thank you for your report; the issue you have reported has just been fixed.

  • In case you see a problem with the fix, please comment on this issue.
  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.

nijel added a commit that referenced this issue Dec 11, 2024
Some files were wrongly licensed after #12172
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adding or requesting a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants