在生产中使用Babel-如何预编译脚本 [英] Using Babel in Production - How to precompile scripts

查看:88
本文介绍了在生产中使用Babel-如何预编译脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Oracle Application Express(APEX)构建应用程序[因此不存在Node].

I'm building an application using Oracle Application Express (APEX) [so no existence of Node].

我有两个问题,它们在概念上是相关的.

I have two issues which are somehow related concept-wise.

问题1:

我在所有页面中都包含了React.js库,以使用其某些功能.

I've included the React.js library in all of my pages to use some of its features.

我正在使用babel将我的JSX转换为简单的JS.一切正常.

I'm using babel to convert my JSX to simple JS. Everything's working fine.

但是我一直在控制台中收到此警告:

But I keep on getting this warning in my console :

You are using the in-browser Babel transformer. 
Be sure to precompile your scripts for production - https://babeljs.io/docs/setup/

我知道我必须预编译我的脚本,但是我不知道该怎么做.我访问了该链接,这让我更加困惑.

I know I must precompile my scripts but I have no idea how. I visited the link and it got me all the more confused.

问题2:

我遇到的另一个问题是,我所有与React相关的代码都存储在一个单独的.js文件中,并使用以下代码将其嵌入到我的页面中:

The other issue I have is that I've got all my react related code in a separate .js file and I have embedded it in my page using this :

<script src="someJSFile.js" type="text/babel"></script>

将类型设置为文本/边框" 会引发此警告:

Setting the type to "text/babel" raises this warning :

Fetching scripts with an invalid type/language attributes is deprecated 
and will be removed in M56, around January 2017. 
See https://www.chromestatus.com/features/5760718284521472 for more details.

此问题是否有解决方法?

Is there any workaround for this issue?

推荐答案

问题1:这与您选择的捆绑程序有关(请参见下面的问题2).无论选择哪种方式,都可以将节点env设置为生产,这会将React置于生产"模式-基本上清除所有不需要的(但有用的)开发消息和检查.

Issue 1: This is linked to what ever bunlder you choose (see issue 2 below). Which ever you do choose, will allow you to set the node env to production, which will put React in "production" mode - basically scraping out all the unneeded (but helpful) development messages and checks.

问题2::一天结束时您将需要一些模块捆绑器.Webpack是目前的定位. Webpack网站

Issue 2: You will need some module bundler at the end of the day. Webpack is the goto at the moment. Webpack Site

替代方法包括:

  • Gulp + Browserify
  • 汇总

我知道您说过无节点".您将不需要节点在服务器上运行任何内容,仅需要在构建文件的本地计算机上运行.节点很容易在几乎任何本地计算机上安装

I know you said "no node". You won't need node to run anything on the server, only on your local machine where you build the files. Node is easy to install on pretty much any local machine

这篇关于在生产中使用Babel-如何预编译脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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