Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4829

Broccoli architecture question: Making new files available to node

$
0
0

@samselikoff wrote:

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:

  1. Read code from the host app’s /mirage directory, turn it from ES6 into CJS
  2. Read code from Mirage’s source, turn it into CJS
  3. 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 serverMiddleware() hook.

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 serverMiddleware().

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 .then() and 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!

Posts: 6

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4829

Trending Articles