By default, React includes many helpful warnings.These warnings are very useful in development.
默認(rèn)情況下React內(nèi)置了很多有用的警告。這些警告對(duì)開發(fā)很有幫助。
However, they make React larger and slower so you should make sure to use the production version when you deploy the app.
但是,它們使React更大更慢,因此您應(yīng)該在部署應(yīng)用程序時(shí)確保使用生產(chǎn)版本。
Create React App 創(chuàng)建React應(yīng)用
If you use Create React App, npm run build will create an optimized build of your app in the build folder.
如果你使用創(chuàng)建React應(yīng)用,npm run build 將會(huì)創(chuàng)建您的應(yīng)用程序的優(yōu)化構(gòu)建到build文件夾。
Webpack Webpack
Include both DefinePlugin and UglifyJsPlugin into your production Webpack configuration as described in this guide.
按照指南上說的那樣把DefinePlugin和UglifyJsPlugin引入到Webpack生產(chǎn)配置中。
Browserify Browserify
Run Browserify with NODE_ENV environment variable set to production and use UglifyJS as the last build step so that development-only code gets stripped out.
運(yùn)行Browserify,將NODE_ENV環(huán)境變量設(shè)置為生產(chǎn)配置,并使用UglifyJS作為最后一個(gè)構(gòu)建步驟,以便只有開發(fā)代碼被刪除。
Rollup Rollup
Use rollup-plugin-replace plugin together with rollup-plugin-commonjs (in that order) to remove development-only code. See this gist for a complete setup example.
使用rollup-plugin-replace插件和rollup-plugin-commonjs(按順序)刪除僅開發(fā)代碼。有關(guān)完整的設(shè)置示例,請(qǐng)參閱此處。