We created a custom Sprockets directive for the Custom Wizard plugin

The Custom Wizard plugin creates its own Ember app and borrows some of the assets from the discourse core.

For that we use a js file called wizard-custom.js with sprockets directives targetting individual files.

In some cases, we require a lot of files from the same folder and were tempted to use require_tree for a long time but unfortunately, that isn’t possible due to the following reasons.

  • The wizard-custom.js file is located inside the plugin, so its load path is different from discourse and we can only require files inside the load path.
  • Sprockets doesn’t allow absolute paths when using require_tree.

Solving this would also mean that the plugin breaks less often, due to changes in discourse core.

To mitigate this, we created a custom sprockets directive called require_tree_discourse which specifically looks up for assets inside the discourse folder using absolute paths. Here’s the PR containing that code.

Thought it would be interesting for discourse devs and rails devs in general out there.

7 Likes

Unfortunately, we had to revert this change, as its not working in production.

It seems like the plugins are loaded a bit later on as compared to when the js files are read.

It does work. We’ll re-introduce the change soon.

4 Likes

We’ve introduced this in our code finally.

4 Likes

Keep in mind, I estimate that within 12 months we will have abandoned sprockets for ember-cli based builds. @eviltrout has already started work investigating the move.

9 Likes

Thanks for the early heads up. Any pointers in that direction will be of great help. cc @angus

3 Likes