在没有webpack或browserify的情况下反应+(Router) [英] React +(Router) without webpack or browserify

查看:85
本文介绍了在没有webpack或browserify的情况下反应+(Router)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以与ReactRouter一起使用react,而无需使用browserify或webpack。
我正在按照 http://rackt.github.io/react-router 中的文档进行操作和react-router( require('react-router'); )。如果我使用browerifly,我生成的捆绑包大约是1MB文件大小,这听起来很多。

Is it possible to use react with ReactRouter, without using browserify or webpack. I am following the documentation from http://rackt.github.io/react-router they require react and react-router (require('react-router');). If I use browerifly my generated bundle is about 1MB filesize, which sounds like a lot.

因此,有可能使reactrouter可以处理CDN中包含已编译JS的< a href = https://cdnjs.cloudflare.com/ajax/libs/react-router/0.13.3/ReactRouter.js> https://cdnjs.cloudflare.com/ajax/libs/react-router/0.13 .3 / ReactRouter.js ,而不是自己捆绑所有要求?如果我尝试使其与CDN一起使用,则会收到未定义Route的错误。

So is it possible to get reactrouter working with including compiled JS from a CDN like https://cdnjs.cloudflare.com/ajax/libs/react-router/0.13.3/ReactRouter.js, instead of bundle all requirements by myself ? If i try to make it work with a CDN, I get an error that Route is not defined. But it looks like it is exported in the cdn file.

我想编译我的JSX / ES6 react组件,包括ReactRouter并从cdn和仅将我的组件捆绑到一个新的js文件中。

I would like to compile my JSX/ES6 react components include the ReactRouter and react JS-files from a cdn and only bundle my components into a new js file.

这是否可行,或者browserify和webpack是设置项目的正确方法吗? (我看了几个github仓库)。我有些怀疑,因为 http://rackt.github.io/react-router/ 上没有安装指南

Is this possible or is browserify and webpack the right way to setup the project ? (I looked at several github repos). I got some doubts because there is no installation guide on http://rackt.github.io/react-router/

像这样的伪html:

<head>
    CND :include react, react-router
    my code combinded.js
</head>


推荐答案

使用CDN的预构建版本时,该库将导出到 window.ReactRouter 。因此, Route 是在 window.ReactRouter.Route 上定义的。

When you're using the prebuilt version from the CDN, the library is exported onto window.ReactRouter. So, Route is defined on window.ReactRouter.Route.

由于React Router也依赖React,因此使用CDN /浏览器版本还需要 React 窗口上可用.React

Since React Router also depends on React, using the CDN/browser build will also require that React is available on window.React.

也就是说,您链接到的CDN版本本身是通过webpack生成的,因此我不希望您获得任何文件尺寸改进。您可能会在browserify捆绑包中查看最小化/死代码消除功能,以查看它是否减小了文件大小。

That said, the CDN version you linked to is, itself, generated with webpack, so I don't expect that you'd gain any file size improvements. You might look into minification/dead code elimination on your browserify bundle to see if it decreases the file size.

这篇关于在没有webpack或browserify的情况下反应+(Router)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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