A platform for community discussion. Free, open, simple.
DEV: Rebuild JS app when files change in discourse-markdown-it (#24379)
David Taylor8c16482932ed
diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.jsindex 4b559747cca..85b91f46959 100644--- a/app/assets/javascripts/discourse/ember-cli-build.js+++ b/app/assets/javascripts/discourse/ember-cli-build.js@@ -14,6 +14,7 @@ const generateWorkboxTree = require("./lib/workbox-tree-builder");const { compatBuild } = require("@embroider/compat");const { Webpack } = require("@embroider/webpack");const { StatsWriterPlugin } = require("webpack-stats-plugin");+const withSideWatch = require("./lib/with-side-watch");const RawHandlebarsCompiler = require("discourse-hbr/raw-handlebars-compiler");process.env.BROCCOLI_ENABLED_MEMOIZE = true;@@ -72,10 +73,10 @@ module.exports = function (defaults) {"node_modules/@discourse/backburner.js/dist/named-amd/backburner.js",},- historySupportMiddleware: false,-trees: {- app: RawHandlebarsCompiler("app"),+ app: RawHandlebarsCompiler(+ withSideWatch("app", { watching: ["../discourse-markdown-it"] })+ ),},});diff --git a/app/assets/javascripts/discourse/lib/with-side-watch.js b/app/assets/javascripts/discourse/lib/with-side-watch.jsnew file mode 100644index 00000000000..459549ba247--- /dev/null+++ b/app/assets/javascripts/discourse/lib/with-side-watch.js@@ -0,0 +1,27 @@+// From https://github.com/cardstack/boxel/blob/d54f834f/packages/host/lib/with-side-watch.js (MIT license)++const mergeTrees = require("broccoli-merge-trees");+const { WatchedDir } = require("broccoli-source");+const Plugin = require("broccoli-plugin");++class BroccoliNoOp extends Plugin {+ constructor(path) {+ super([new WatchedDir(path)]);+ }+ build() {}+}++/*+ Doesn't change your actualTree, but causes a rebuild when any of opts.watching+ trees change.++ This is helpful when your build pipeline doesn't naturally watch some+ dependencies that you're actively developing. For example, right now+ @embroider/webpack doesn't rebuild itself when non-ember libraries change.+*/+module.exports = function withSideWatch(actualTree, opts) {+ return mergeTrees([+ actualTree,+ ...opts.watching.map((w) => new BroccoliNoOp(w)),+ ]);+};