Monday, February 15, 2021
1 change · master
New functionality added to Odoo
Odoo now supports writing browser code with modern JavaScript modules while still packaging it for Odoo’s dynamic app system. This improves developer productivity through better editor assistance, easier refactoring, and sourcemaps that keep debugging practical in asset debug mode.
Original PR description
Because of the way Odoo works at its core, we do not know before hand which files will be loaded as an asset in the browser, because it depends on the installed Odoo addons. This is why it is…
Because of the way Odoo works at its core, we do not know before hand which files will be loaded as an asset in the browser, because it depends on the installed Odoo addons. This is why it is historically difficult to integrate Odoo with standard JS tooling, and this is why Odoo needs to use a custom javascript module system. However, there is a way to use native JS modules (and gain all the benefits from it: IDE autocompletion, ease of refactoring, intellisense, ...): we can write JS as native JS modules, but convert them at runtime into Odoo custom modules. This is exactly the strategy applied by this PR. This has a lot of benefits, but there is a downside: we can no longer serve statically JS files in debug=assets. This would be a dealbreaker, if we did not have sourcemaps. So, this PR introduces - support for native JS modules - add a specific asset controller `/web/assets/` - generate sourcemaps (for debug=assets mode) Note that part of the complexity of this work is cause by the debug=assets mode, where we need to have a fixed route for the debug asset bundle (so we do not lose breakpoints when debugging), but we still need to safely regenerate the bundles whenever the JS code is modified.