ES6 global import

后端 未结 2 1005
悲&欢浪女
悲&欢浪女 2021-01-01 17:59

What is the best way to import some modules in all of the files of the project, so I don\'t have to write stuff like:

import React from \'react\';
import Ref         


        
相关标签:
2条回答
  • 2021-01-01 19:05

    Create a "base" that declares common imports, then you can import that one file.

    0 讨论(0)
  • 2021-01-01 19:06

    The other answer covers this, but not with valid ES6, so I'm adding my own. Make a central file to import your react components, in some central react.js file

    export {default as React} from 'react';
    export {default as Reflux} from 'reflux';
    export {default as reactMixin} from 'react-mixin';
    

    Then in the files where you need to use these three, you could do

    import {React, Reflux, reactMixin} from './react';
    

    to import all three into your component file.

    0 讨论(0)
提交回复
热议问题