I am converting some code to ES6 syntax using JSPM/SystemJS/BabelJS.
I have the following:
// main.js:
console.log('foo');
import * as Backbone from 'backbone';
import * as Cocktail from 'backbone.cocktail';
Cocktail.patch(Backbone);
console.log('bar');
import Application from 'background/application';
console.log('application:', Application);
// application.js:
console.log('baz');
export default {};
This code outputs baz
foo
bar
application: {}
.
I would like to output: foo
bar
baz
application: {}
such that Cocktail.patch
is ran before any code in application.js
I am able to achieve this by re-writing my code as:
// main.js:
console.log('foo');
import * as Backbone from 'backbone';
import * as Cocktail from 'backbone.cocktail';
Cocktail.patch(Backbone);
console.log('bar');
System.import('background/application').then(function(Application){
console.log('application:', Application.default);
});
// application.js:
console.log('baz');
export default {};
However, this feels convoluted and incorrect. It's leveraging SystemJS explicitly rather than ES6 import/export syntax. How can I wait before parsing application.js
using ES6 syntax?