vendredi 24 novembre 2017

Generating additional js file to be shared with Ember app

I would like my Ember app to generate an extra javascript file that can be consumed by non-ember apps, so the code can be shared without creating an extra project just for it.

Inside the app, I create a public folder with two files, index.js and notifications.js to test if the pipeline is working:

/app
  /public
     index.js
     notification.js

And the files:

//notification.js
export function test(){console.log('test')}

//index.js
import {test} from "./notifications"; 

window.console.log('loading...'); $(document).ready(function() { window.console.log('initializing...'); window.test = test; }); Then in ember-cli-build file I create as a new output:

// ember-cli-build
app.import('app/public/index.js', { outputFile: 'assets/public.js' });

The transpiling seems to be working ok, but just creates a module out of index.js to be imported inside the app

 define('app/public/index', ['app/public/notifications'], function (_notifications) {
  'use strict';

  window.console.log('loading...');

  $(document).ready(function () {
    window.console.log('initializing...');
    window.test = test;
  });
});//# sourceMappingURL=public.map

How can I generate a lib that can be consumed directly in the browser?




Aucun commentaire:

Enregistrer un commentaire