Code Monkey home page Code Monkey logo

pingtest's Introduction

React Transform Boilerplate

react-transform channel on Discord

🚀 Now with Babel 6 support (thanks @justingreenberg)

This project is a reference implementation of babel-plugin-react-transform. It can be used as a boilerplate for quickly getting a new project up and running with a few useful transforms:

For convenience they are packed in a single preset called react-transform-hmre but you can make your own.

Syntax errors are displayed in an overlay using @glenjamin’s webpack-hot-middleware, which replaces Webpack Dev Server. This project does not use React Hot Loader.

Demo

react-transform-boilerplate

Installation

git clone https://github.com/gaearon/react-transform-boilerplate.git
cd react-transform-boilerplate
npm install
npm start
open http://localhost:3000

Transforms are enabled for files inside src (except index.js).

FAQ

Do I need to use it in my React project?

No! This is experimental stuff. It’s not polished, it doesn’t work in all browsers, the docs are poor, and it presumes you understand how Babel, Webpack, React, and other tools can work together. If you’re a beginner, we suggest you to work with more simple and stable boilerplates, and come back when you’re comfortable with them and want to experiment with your own tooling.

Should I run this on the server / in tests / in production?

No! This is only meant for client development environment. Make sure your NODE_ENV is neither development nor empty in these environments. Alternateively you can put the Babel configuration under a different env key and use your custom NODE_ENV or BABEL_ENV to turn these transforms on. Or you can embed Babel configuration inside the Webpack config . No matter how you do it, make sure you’re only running this transform in client-side development mode, and it is disabled on the server, in tests, and in production.

I can’t serve images, use different HTML, add CSS, etc.

This project is a reference implementation of babel-plugin-react-transform—it is just a Webpack bundle served by an Express server. It’s not meant to demonstrate every feature of either project. Please consult Webpack and Express docs to learn how to serve images, or bundle them into your JavaScript application.

My server is throwing a 404 after npm run build

Again, this boilerplate is not intended to be production ready. The 404 is because index.html is hard coded with the webpack bundle path in /static/ (used by development server). You must manually update the script tag in index.html with the correct bundle path of /dist/bundle.js in order to use compiled source.

What errors does it catch?

react-transform-catch-errors catches runtime errors inside render() method of React componets it detects. Webpack Hot Middleware catches syntax errors anywhere in the module.

These are two different tools and you need to be aware of that.

Can I use WebpackDevServer with this?

Absolutely! We only show Express server with webpack-dev-middleware and webpack-hot-middleware because people often have a Node server anyway, and it can be tricky to configure WebpackDevServer to work with existing server. Additionally, webpack-hot-middleware displays syntax errors in an overlay, which WebpackDevServer doesn’t do.

However you can use WebpackDevServer instead of the custom server just fine.

I don’t see the syntax error overlay

Make sure your react-app is not attached to document.body. The client overlay provided by webpack-hot-middleware will render into document.body.

Attaching the React root node to document.body requires extra caution, as many third-party packages will append their markup to the body as well. React will replace the entire contents in the body on every re-render. Thus you will not see the additional markup.

It’s always better to render your React app in a #root DOM element.

import React from 'react'
import { render } from 'react-dom'
import { App } from 'app'
     
render(<App />, document.getElementById('root'))

Discussion

You can discuss React Transform and related projects in #react-transform channel on Reactiflux Discord.

License

CC0 (public domain)

pingtest's People

Contributors

gaearon avatar jamiebuilds avatar justingreenberg avatar danmartinez-mw avatar chentsulin avatar clkao avatar clessg avatar n1ghtmare avatar hugooliveirad avatar ianmcnally avatar joearasin avatar rf- avatar ryanwholey avatar tylerhellner avatar vesakilp avatar zillding avatar arve0 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.