1
//Govegan.js
console.log('inside Govegan.js');
export function MyLife(){
//empty funciton
}
//index.js
import React from 'react';
import ReactDOM from 'react-dom';
import {Govegan} from './Govegan';
class App extends.React.Component{
render(){
return(<div>Hello</div>);
}
}
ReactDOM.render(<App/>, document.getElementById('app'));
//console output: inside Govegan.js
Console.log在MyLife函数仍然在index.js中运行之前,即使我们只是导入了一个空的MyLife函数。为什么导入的项目中未包含的代码仍然运行?
您也可以导出常量,因此节点需要在整个文件中运行代码才能正确导出所有内容,您的情况是导出一个函数,但正如我所说的,节点需要运行所有内容以查找是否还有别的东西需要导出。 – Crysfel