I’m working on a feature for Mirage, that will make some Mirage code available to Node so that it can be used in an Express middleware.
I’d like some advice on how best to write the Broccoli code.
At a high level, here’s my current thinking on what needs to happen:
- Read code from the host app’s
/miragedirectory, turn it from ES6 into CJS
- Read code from Mirage’s source, turn it into CJS
require()code from those places in the
serverMiddleware()hook, instantiate a new Mirage server with config from the host app, and go from there
I’m trying to start out with just #2 – ignoring the host app for now, and just getting the Mirage server code written to CJS in a place where I can
require() it from the
What’s the right way to think about this?
In my experimenting so far, I followed some other addons and used Rollup via
broccoli-rollup to read in
ember-cli-mirage/addon/server.js (which is sort of the entry point for Mirage), and wrote it to CJS.
Where I’m getting confused is, where I can/should write this CJS file so that I can reliably “get” to it in
In general, since
serverMiddleware doesn’t get a tree I feel confused about how that hook can interact with files created at build-time. I also sometimes reach for something like a
.then method on my broccoli trees, but don’t know if that’s possible or a recommended pattern. (In other words, once I write my CJS file, if I could
require() it, I could throw some instance data onto
this and access it like that from
serverMiddleware. Feels hacky, but it could get me unstuck.)
Any recommendations here? Really appreciate it!