最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to import everything from a module in react using es6? - Stack Overflow

programmeradmin3浏览0评论

I am using brace which is a npm module for theming in ace editor. Currently, I am importing each theme using

import 'brace/theme/solarized_dark';

How do I import all the themes as I need to give the user the option to pick any theme.

I am using brace which is a npm module for theming in ace editor. Currently, I am importing each theme using

import 'brace/theme/solarized_dark';

How do I import all the themes as I need to give the user the option to pick any theme.

Share Improve this question asked Oct 24, 2017 at 10:59 umanuman 1931 gold badge2 silver badges11 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 16

Create one brace/themes/index.js and export the things that you want to acess

export * as theme1 from './theme1';
export * as theme2 from './theme2';
....

Then import from that folder : (name is index.js so no need to give full path to the file)

import * as SolDark 'brace/themes'; // by default get index.js

Then you can access each method like :

SolDark.theme1;
SolDark.theme2;

I don't know how does your file structure look like, but lets assume it is something like that

|brace |---theme | |---theme1 | |---theme2 | | ... | |---solarized_dark

Then you could create index.js in the theme folder and inside it:

//index.js
export {default as theme1} from './theme1';
export {default as theme2} from './theme2';

assuming you have default exports.

Then in other files you just simply do:

//other_file.js
import {theme1, theme2} from 'someRelativePath/brace/theme/index'

or

import * as themes from 'someRelativePath/brace/theme/index'
发布评论

评论列表(0)

  1. 暂无评论