2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-04 01:15:08 +08:00
discourse/frontend/asset-processor
David Taylor af3385baba
DEV: Introduce new rollup-based plugin build system (#35477)
This commit introduces a new build system for plugins, which shares a
large amount of code with the recently-modernized theme compiler.
Plugins are compiled to native ES Modules, and loaded using native
`import()` in the browser, just like themes.

To achieve inter-plugin imports, each bundled plugin entrypoint
implements a custom 'module federation' interface. Each export from
internal plugin modules is made available as a specially-named export on
the entrypoint. When modules in another plugin's namespace are imported,
they are automatically rewritten to use these federated entrypoints.

This change should be almost 100% backwards-compatible. There are some
edge cases which will behave differently, since modules are now eagerly
evaluated according to the ESM spec, instead of being lazily required
via asynchronous-module-definitions (AMD).

The native ESM format should also provide a performance improvement. The
old AMD system involved lots of nested function calls when booting the
app. Now, all the source modules are bundled up into a single ESM bundle
with minimal stack depth.

The build system implements a filesystem-based cache. That means that if
the plugin javascript files are unchanged, they will not need to be
recompiled, even after restarting the Rails server. This mimics the
behaviour of the theme system. Similarly, in production builds, existing
files will be automatically reused if they exist. In future, we plan to
include pre-built copies of common plugins in our prebuild-asset
bundles.

Initially, this new compiler is disabled by default. To test it, we can
set the `ROLLUP_PLUGIN_COMPILER=1` environment variable. We'll continue
to test, improve and document the system before enabling it by default.

---------

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
Co-authored-by: Chris Manson <chris@manson.ie>
2026-03-03 13:50:55 +00:00
..
rollup-plugins DEV: Introduce new rollup-based plugin build system (#35477) 2026-03-03 13:50:55 +00:00
add-theme-globals.js
add-theme-globals.test.mjs
babel-replace-imports.js DEV: Introduce new rollup-based plugin build system (#35477) 2026-03-03 13:50:55 +00:00
babel-replace-imports.test.mjs
build.js
content-tag.js
federated-modules-helper.js DEV: Introduce new rollup-based plugin build system (#35477) 2026-03-03 13:50:55 +00:00
noop.js
package.json DEV: Update node engine requirement to >= 20 across all packages (#38151) 2026-03-02 15:17:29 -03:00
postcss-variable-prefixer.js
postcss.js
rollup-virtual-imports.js DEV: Introduce new rollup-based plugin build system (#35477) 2026-03-03 13:50:55 +00:00
shims.js
theme-hbs-ast-transforms.js
theme-rollup.js DEV: Introduce new rollup-based plugin build system (#35477) 2026-03-03 13:50:55 +00:00
transpiler.js
url-polyfill.js