DEV: Rebuild JS app when files change in discourse-markdown-it (#24379)

Based on a workaround shared in https://github.com/embroider-build/embroider/issues/1635#issue-1935759857
This commit is contained in:
David Taylor 2023-11-17 18:55:14 +00:00 committed by GitHub
parent 0c712eaa3a
commit 8c16482932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View File

@ -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"] })
),
},
});

View File

@ -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)),
]);
};