在目录的根目录(例如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/
最佳答案
经过大量的撞击之后,我们更换了
export {default as SampleOne} from './SampleOne/SampleOne';
export {default as SampleTwo} from './SampleTwo/SampleTwo';
与
import {default as SampleOne} from './SampleOne/SampleOne';
import {default as SampleTwo} from './SampleTwo/SampleTwo';
export {SampleOne, SampleTwo};
这似乎对我们有用。
关于reactjs - 立即导出ES6(React,Webpack,Babel),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35945730/