0.7 Development and Production Versions 开发和生产版本

By default, React includes many helpful warnings.These warnings are very useful in development.

默认情况下React内置了很多有用的警告。这些警告对开发很有帮助。

However, they make React larger and slower so you should make sure to use the production version when you deploy the app.

但是,它们使React更大更慢,因此您应该在部署应用程序时确保使用生产版本。

Create React App 创建React应用

If you use Create React App, npm run build will create an optimized build of your app in the build folder.

如果你使用创建React应用,npm run build 将会创建您的应用程序的优化构建到build文件夹。

Webpack Webpack

Include both DefinePlugin and UglifyJsPlugin into your production Webpack configuration as described in this guide.

按照指南上说的那样把DefinePlugin和UglifyJsPlugin引入到Webpack生产配置中。

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.

运行Browserify,将NODE_ENV环境变量设置为生产配置,并使用UglifyJS作为最后一个构建步骤,以便只有开发代码被删除。

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(按顺序)删除仅开发代码。有关完整的设置示例,请参阅此处。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容