React +(Router) 没有 webpack 或 browserify [英] React +(Router) without webpack or browserify

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

问题描述

是否可以在不使用 browserify 或 webpack 的情况下使用 ReactRouter.我正在关注 http://rackt.github.io/react-router 的文档,他们需要 react 和 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 一起工作,例如 https://cdnjs.cloudflare.com/ajax/libs/react-router/0.13.3/ReactRouter.js,而不是自己捆绑所有需求?如果我尝试让它与 CDN 一起工作,我会收到一个错误,指出 Route 未定义.不过貌似是在cdn文件里导出的.

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 的 React JS 文件,并且只将我的组件捆绑到一个新的 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/浏览器构建还需要 Reactwindow.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.

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

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