Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

javascript - 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(){}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...