Reputation: 10298
I have moduleA which exports some functions:
// moduleA.js
export function f1() {...}
export function f2() {...}
Is there any way to re-export all exports of moduleA in moduleB and make it looks like one object:
// moduleB.js
export * as a from 'moduleA'; // pseudo code, doesn't work
So that I can use it in this way?
// main.js
import {a} from 'moduleB';
a.f1();
a.f2();
Upvotes: 15
Views: 5299
Reputation: 10997
file1.js
export let uselessObject = {
con1 : function () {
console.log('from file1.js')
}
}
file2.js
import { uselessObject } from './file1.js'
uselessObject.con2 = function(){
console.log('from file2.js ')
}
export { uselessObject } from './file1.js'
Index.js
import { uselessObject } from './file2.js'
uselessObject.con1()
uselessObject.con2()
Output
from file1.js
from file2.js
Upvotes: -2
Reputation: 816262
The syntax is not supported yet but there is a proposal for it.
You can use it now with Babel.js or simply do:
import * as a from '...';
export {a};
Upvotes: 26