在一个目录的根目录下(例如components/
,containers/
),我有一个index.jsx
文件,它立即导出所有组件,以便我可以像这样导入它们:
import {SampleOne, SampleTwo} from '../components'.
然而,根目录下的index.jsx
文件无法使用以下方法:
import SampleOne from './SampleOne/SampleOne';
import SampleTwo from './Sample/SampleTwo';
export default {
SampleOne,
SampleTwo
};
因此,我将其转换为以下内容(基本上相同):
export {default as SampleOne} from './SampleOne/SampleOne';
export {default as SampleTwo} from './SampleTwo/SampleTwo';
这个方案可行,但我收到了一个警告:
Can't make class (SampleOne & SampleTwo) hot reloadable due to being read-only.
To fix this you can try two solutions. First, you can exclude files or directories
(for example, /node_modules/) using 'exclude' option in loader configuration.
Second, if you are using Babel, you can enable loose mode for `es6.modules` using
the 'loose' option. See: http://babeljs.io/docs/advanced/loose/
and http://babeljs.io/docs/usage/options/
default
导出。 - a better oliver