user9597092
user9597092

Reputation:

Angular 2+ having a master import file

I have difference files with data like this:

export const config1 = { stuff here }
export const config2 = { other stuff here }
export const config3 = { other stuff here }

Then I import them:

import { config1 } from 'some path';
import { config2 } from 'some path';
import { config2 } from 'some path';

What I what to do is to have like an index file that has all the imports so I just import 1?

So instead of the above I just need to do

import { whatever } from 'path'

Then I use it like:

whatever.config1....

How can I do this?

Upvotes: 1

Views: 29

Answers (1)

FAISAL
FAISAL

Reputation: 34673

Create a file e.g. configs.ts and export from that like:

export * from 'some path for config1';
export * from 'some path for config2';
export * from 'some path for config3';

Then you can import from this one file:

import { config1, config2, config3, whatever_else } from './path/to/configs';

Upvotes: 2

Related Questions