13
我有一個React應用程序,它有許多導入相同模塊的組件。 webpack是否會爲每個請求它的文件導入每個模塊,導致重複的代碼(在這種情況下,每個模塊每次導入兩次,只是兩個組件)?我正在考慮重寫組件,以便子組件不需要React模塊,但也許我正在解決一個不存在的問題。如果導致重複的代碼,我想避免許多導入相同的反應模塊。webpack如何處理導入同一模塊的多個文件React
組分1
import React from "react";
import { Link } from "react-router";
import ReactLogo from "elements/ReactLogo";
export default class MainMenu extends React.Component {
render() {
return <div>
<ReactLogo type="svg" /> <ReactLogo type="png" /> <ReactLogo type="jpg" />
<h2>MainMenu:</h2>
<ul>
<li>The <Link to="home">home</Link> page.</li>
<li>Do something on the <Link to="todo">todo page</Link>.</li>
<li>Switch to <Link to="some-page">some page</Link>.</li>
<li>Open the chat demo: <Link to="chat" params={{room: "home"}}>Chat</Link>.</li>
<li>Open the page that shows <Link to="readme">README.md</Link>.</li>
</ul>
</div>;
}
}
組分2導入相同的3個模塊。
import React from "react";
import { Link } from "react-router";
import ReactLogo from "elements/ReactLogo";
export default class MainMenu extends React.Component {
render() {
return <div>
<ReactLogo type="svg" /> <ReactLogo type="png" /> <ReactLogo type="jpg" />
<h2>MainMenu:</h2>
<ul>
<li>The <Link to="home">home</Link> page.</li>
<li>Do something on the <Link to="todo">todo page</Link>.</li>
<li>Switch to <Link to="some-page">some page</Link>.</li>
<li>Open the chat demo: <Link to="chat" params={{room: "home"}}>Chat</Link>.</li>
<li>Open the page that shows <Link to="readme">README.md</Link>.</li>
</ul>
</div>;
}
}
爲什麼然後在每個文件中重複導入? –
對不起,但我正在處理,我的代碼包含倍數。我不知道如何修復它。我在es6中的所有文件都有200kb的大小(全部都是這樣),我的「捆綁」文件有1.3mb @trekforever – jrodriguez
因此React是否在導入它的每個組件上都有重複? – stackjlei