Share application code between Node and Ember 2.x

I have an app which uses a Node backend and Ember 2.3 frontend - So there is common code which needs to be shared between Node and Ember.

I think this question is related to Best practice for sharing ES6 code between a node server and an Ember client but my Node code doesn’t use ES6 style imports and this existing discussion too was in search of a seamlessly integration with ember-cli.

Here’s something I’ve been trying.

Suppose the node code to share is located at:

project/nodeserver/node_modules/shared-code.js

Step 1: Bundle the Node code and place it at:

project/ember-app-name/app/node-shares/shared-code.js

This step would involve bundling it using a tool like browserify but the generated code needs to use ES6 style exports.

Step 2. In ember add an import in ember-cli-build.js:

app.import('ember-app-name/node-shares/shared-code.js');

Step 3. To use the library in ember:

import foo from 'ember-app-name/node-shares/shared-code';

Steps 2 and 3 work (thanks to this tip: http://stackoverflow.com/a/32591830/1208799)

How do you achieve Step 1 so that its integrated with the ember-cli build system?