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

feat: New Build System based on esbuild #12883

Merged
merged 73 commits into from May 18, 2021

Conversation

netchampfaris
Copy link
Contributor

@netchampfaris netchampfaris commented Apr 17, 2021

A new build system based on the Go-based Javascript bundler https://github.com/evanw/esbuild.

  1. Deprecated the use of build.json
  2. *.bundle.* files placed anywhere in the public folder are bundled
    Files types supported: .js, .ts, .css, .scss, .sass, .less, .styl
  3. Built files are created in public/dist folder which is gitignored
    This means every JS/CSS asset will always be under it's respective app folder in the assets folder. For e.g., desk.js will be at /assets/frappe/dist/js/desk.bundle.js. Previously, it was at /assets/js/desk.min.js.

Build Stats

Macbook Pro 15 inch 2019, 2.6 GHz 6-Core Intel Core i7, 16GB RAM

Build using rollup: 48.31s
~/Projects/benches/frappe-bench/apps/frappe esbuild
❯ bench build --app frappe
yarn run v1.22.4
$ node rollup/build.js --app frappe
Development mode
✔ Built js/moment-bundle.min.js
✔ Built js/libs.min.js

Building frappe assets...

✔ Built js/checkout.min.js
✔ Built js/dialog.min.js
✔ Built js/list.min.js
✔ Built js/web_form.min.js
✔ Built js/user_profile_controller.min.js
✔ Built js/frappe-recorder.min.js
✔ Built js/barcode_scanner.min.js
✔ Built js/bootstrap-4-web.min.js
✔ Built js/chat.js
✔ Built js/control.min.js
✔ Built js/report.min.js
✔ Built js/data_import_tools.min.js
✔ Built js/frappe-web.min.js
✔ Built js/desk.min.js
✔ Built css/frappe-rtl.css
✔ Built css/report.min.css
✔ Built css/frappe-chat-web.css
✔ Built css/web_form.css
✔ Built js/form.min.js
✔ Built css/printview.css
✔ Built css/email.css
✔ Built css/login.css
✔ Built css/frappe-web-b4.css
✔ Built css/desk.min.css
✨  Done in 43.753s
✨  Done in 48.31s.
Build using esbuild: 3.948s (~12x faster)
~/Projects/benches/frappe-bench/apps/frappe esbuild 55s
❯ node esbuild
frappe/public/build/js/controls.bundle.js 1087.445 Kb
frappe/public/build/js/desk.bundle.js 995.973 Kb
frappe/public/build/js/desk.bundle.css 423.239 Kb
frappe/public/build/js/form.bundle.js 1173.14 Kb
frappe/public/build/js/frappe-web.bundle.js 439.292 Kb
frappe/public/build/js/libs.bundle.js 981.026 Kb
frappe/public/build/js/list.bundle.js 169.587 Kb
frappe/public/build/js/report.bundle.js 170.955 Kb
Build time: 3.948s

DigitalOcean $5 Droplet, 1vCPU, 1GB RAM

Build using rollup: 386.77s
frappe@frappe-esbuild-test:~/frappe-bench/apps/frappe$ bench build --app frappe
yarn run v1.22.10
$ FRAPPE_ENV=production node rollup/build.js --app frappe
Production mode
✔ Built js/moment-bundle.min.js
✔ Built js/libs.min.js

Building frappe assets...

✔ Built js/checkout.min.js
✔ Built js/dialog.min.js
✔ Built js/web_form.min.js
✔ Built js/user_profile_controller.min.js
✔ Built js/list.min.js
✔ Built js/chat.js
✔ Built js/frappe-recorder.min.js
✔ Built js/barcode_scanner.min.js
✔ Built js/bootstrap-4-web.min.js
✔ Built css/frappe-rtl.css
✔ Built css/report.min.css
✔ Built js/data_import_tools.min.js
✔ Built js/frappe-web.min.js
✔ Built css/frappe-chat-web.css
✔ Built js/report.min.js
✔ Built css/web_form.css
✔ Built js/control.min.js
✔ Built js/desk.min.js
✔ Built css/printview.css
✔ Built css/email.css
✔ Built css/login.css
✔ Built css/frappe-web-b4.css
✔ Built js/form.min.js
✔ Built css/desk.min.css
✨  Done in 383.035s
Done in 386.77s.
Build using esbuild: 15.510s (~25x faster)
frappe@frappe-esbuild-test:~/frappe-bench/apps/frappe$ node esbuild
frappe/public/build/js/controls.bundle.js 1088.901 Kb
frappe/public/build/js/desk.bundle.js 997.065 Kb
frappe/public/build/js/desk.bundle.css 421.238 Kb
frappe/public/build/js/form.bundle.js 1175.061 Kb
frappe/public/build/js/frappe-web.bundle.js 438.942 Kb
frappe/public/build/js/libs.bundle.js 981.026 Kb
frappe/public/build/js/list.bundle.js 171.251 Kb
frappe/public/build/js/report.bundle.js 170.798 Kb
Build time: 15.510s

Features

CLI Output

image

Build Events in browser

WIP

  • Make it work for all apps
  • Handle libs.min.js
  • Add watch mode
    • Show build events in browser
    • Update assets_json directly in redis as files change
  • Fix the URL of all lazy-loaded bundles across the codebase
  • Convert Class.extend to ES6 class across the codebase
  • Better CLI output
  • Hash-based file naming for better HTTP caching and cache-busting
  • Production mode
  • Support for built assets download
  • Remove rollup related code
  • Docs explaining how the build system works (Asset bundling docs frappe_docs#129)
  • ERPNext PR

Other changes

  • CSS for emails is now picked from hooks.py. Previously it was picked from hardcoded paths [app]/public/email.css

Documentation

@surajshetty3416 surajshetty3416 changed the title feat: New Build System based on esbuild build: New Build System based on esbuild Apr 17, 2021
@netchampfaris netchampfaris changed the title build: New Build System based on esbuild feat: New Build System based on esbuild Apr 17, 2021
- Deprecate use of build.json
- *.bundle.js files placed anywhere in the public folder are bundled
- Built files are created in public/build folder which is gitignored

WIP
- add support for multiple file types
Previously email.css files were explicitly picked from hardcoded path
like public/css/email.css for all apps
Ignore the commit which replaces use of Class.extend with native class
in git blames
Jinja helpers to load js, css assets
@surajshetty3416
Copy link
Member

Convert Class.extend to ES6 class across the codebase

+1 for this 🎉

- Promisify frappe.require
- Separate file to import jquery and bootstrap
- Remove separate jquery bundle from app as well as web
- Load jquery from node_modules
- basic watch mode
- Node paths include all app node_modules and app folders
- rename output directory to "dist"
- output files in flat directories: dist/js and dist/css
- For better HTTP caching and cache busting
- assets.json is created under [app]/dist folder which contains the map
of input file and output file name, this is used to get the correct path for
bundled assets
@surajshetty3416 surajshetty3416 merged commit e9cf28b into frappe:develop May 18, 2021
@surajshetty3416 surajshetty3416 deleted the esbuild branch May 18, 2021 11:29
@centaur78
Copy link

hi @netchampfaris

just did a bench update.

The quotation doctype seems to be blank
image

below is console error

image

@netchampfaris
Copy link
Contributor Author

@centaur78 Thanks for reporting. Fixed frappe/erpnext#25753

@sagarvora
Copy link
Member

My preliminary issues with esbuild so far:

  • esbuild uses a polling based file watcher which is not as performant as rollup (causes development lags). It also seems to be rebuilding CSS files unnecessarily when JS code is modified. To solve this, we could maybe write our own watcher based on something like chokidar
  • CSS sourcemaps are not yet supported.

surajshetty3416 added a commit that referenced this pull request Aug 4, 2021
@vrslev
Copy link
Contributor

vrslev commented Sep 19, 2021

@netchampfaris Hello! Are there plans to backport this to v13?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants