9

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.

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

1 Comment

I think you missed a from in import * as SolDark 'brace/themes'; => import * as SolDark from 'brace/themes';
0

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'

2 Comments

Is there any other way I don't want to create files in the node_modules folder. Also is importing each file the only option in any situation.
You could create a file called, for example themeUtils.js and put it anywhere in your file structure, for example src/utils. In this file you do what in my example is done in the index.js. I don't believe there is a simplier way of importing everything at once if there is no such an export in the npm package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.