简体   繁体   English

如何在浏览器中为 Redux Toolkit 开启生产模式?

[英]How do you turn on Production mode for Redux Toolkit in the browser?

I really am loving the Redux Toolkit, but it has some warnings that I know I can safely ignore (non-serializable values in an action being sent to some thunks; in this case an API) but I want to make sure they do not show up in the shipped application.我真的很喜欢 Redux Toolkit,但它有一些警告我知道我可以安全地忽略(发送到某些 thunk 的操作中的不可序列化值;在这种情况下是 API)但我想确保它们不显示在附带的应用程序中。

I can't seem to find how to turn on production mode which would skip the "serializable-state-invariant-middleware" when I deploy a finished version to the browser.我似乎无法找到如何打开生产模式,当我将完成的版本部署到浏览器时,该模式会跳过“可序列化状态不变中间件”。 I know I could modify the list of middleware to avoid it, but that seems really clunky.我知道我可以修改中间件列表来避免它,但这看起来很笨拙。

I'm the creator and maintainer of Redux Toolkit.我是 Redux Toolkit 的创建者和维护者。

Like most libraries in the NPM ecosystem, production mode is detected based on process.env.NODE_ENV being set to 'production' .与 NPM 生态系统中的大多数库一样,生产模式是根据process.env.NODE_ENV设置为'production'来检测'production' This happens automatically in most build tools, such as Webpack's mode: 'production'这在大多数构建工具中会自动发生,例如 Webpack 的mode: 'production'

Create-React-App and other meta-build frameworks also ensure this is set automatically, so you shouldn't have to worry about it. Create-React-App 和其他元构建框架也确保这是自动设置的,因此您不必担心。

You can review the contents of a production bundle using source-map-explorer to help confirm that it's behaving as expected.您可以使用source-map-explorer查看生产包的内容,以帮助确认它的行为是否符合预期。

(Also, note that the "non-serializable values in actions" message with createAsyncThunk is a bug that we will be fixing shortly .) (另外,请注意createAsyncThunk的“操作中的不可序列化值”消息是一个我们将很快修复的错误。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM