Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 how to export all item from one file

I want to export all methods of a file from another file.

currently I am doing this, and it works. How can I merge below two into 1 export expression

import  * as db  from './web/query';
export default db;

I tried below written 1 line exports but all failed

export *   from './web/query';  //==error
export *  as default  from './web/query';  //==error
export *  as {default}  from './web/query';  //==error
export from from './web/query'; //== error
export default from './web/query'; //== error

Error means

import db from '../db/index';

db is undefined here. However the the first methods works

Inside of file './web/query' looks like

export function foo(){}
export function baar(){}
like image 662
Praveen Prasad Avatar asked Sep 12 '25 06:09

Praveen Prasad


1 Answers

You cannot in ES2016. To create a module namespace object, you need to give it an identifier (like db) in your current module scope, and then re-export that. There's no way around it.

There is however a stage 1 proposal to add the export * as default from … syntax you were trying.

like image 119
Bergi Avatar answered Sep 14 '25 19:09

Bergi