Browserify / Babelify反应生产(NODE_ENV生产) [英] Browserify/Babelify React for production (NODE_ENV production)

查看:586
本文介绍了Browserify / Babelify反应生产(NODE_ENV生产)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行此命令:

browserify src.js -t [ babelify --presets [ react ] ] > build.js

和我得到能够由它自己使用的一个文件。做工精细,但它的NODE_ENV设置为开发和我得到一个有关下载阵营DevTools的console.log。

and I get a single file that can be used by it's own. Works fine, but it's NODE_ENV is set to development and I get a console.log about downloading React DevTools.

我如何将它设置为生产?我浏览周围并没有发现任何东西,为我工作。我试过envify,但没有运气(我很福利局与JS版本)。

How do I set it to production? I browsed around and didn't find anything that worked for me. I tried envify, but no luck (I'm very newb with JS builds).

我试图把--NODE_ENV生产某处上面的行,但我很新的browserify和babelify所以我基本上是做一个试验和错误。

I tried putting --NODE_ENV production somewhere in the line above, but I'm very new to browserify and babelify so I'm basically doing a trial and error.

推荐答案

您设置 NODE_ENV 的生产。

我的生产脚本通常看起来是这样的,没有什么太壮观了。

My production script usually looks something like this, nothing too spectacular

NODE_PATH=./src/components:./src NODE_ENV=production browserify ./src/app.js --extension .jsx -t babelify -t brfs | uglifyjs > ./dist/main.js

请注意,这并不需要 envify ,虽然的文档表明,它应该。你可以简单地通过改变 NODE_ENV 别的东西,别的测试这并做出反应引发devtools警告,但制作设置不即使 envify 不包含在变换。有可能是测试一个更好的方式无论是在生产模式时作出反应,或文档可能不是最新的,这是与阵营0.14.0测试。

Note that this does not require envify, although the documentation suggests that it should. You can test this simply by changing the NODE_ENV to something else, anything else and React throws the devtools warning, but with production set it does not even though envify is not included in the transforms. There may be a better way of testing whether React is in production mode, or the documentation may not be up to date, this is tested with React 0.14.0.

修改的阵营指定自己的 browserify 配置它增加了 envify 变换,因此为什么它的工作原理。我一直前款不变,因为它不是立即显而易见的,为什么这一切作品,而这一段希望清除它。

edit React specifies its own browserify config which adds the envify transform, hence why it works. I have kept the above paragraph untouched as it is not immediately obvious why this all works, and this paragraph hopefully clears it up.

这篇关于Browserify / Babelify反应生产(NODE_ENV生产)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆