Giter Club home page Giter Club logo

Comments (25)

devongovett avatar devongovett commented on May 3, 2024 10

jsx is a supported file extension. you just need to setup babel in your project by adding a .babelrc, and install babel-preset-react

from parcel.

mjackson avatar mjackson commented on May 3, 2024 5

Another example is here https://github.com/jaredpalmer/react-parcel-example

from parcel.

reicheltp avatar reicheltp commented on May 3, 2024 4

Hi @NullVoxPopuli
I've created a minimal React example. Take a look: https://github.com/reicheltp/parcel-react-example

from parcel.

queicherius avatar queicherius commented on May 3, 2024 4

Just chiming in that a react example with hot reloading would be super neat since that is the only thing that the competition (create-react-app) can't easily provide. Some opportunity here. :)

from parcel.

devongovett avatar devongovett commented on May 3, 2024 3

I'm thinking of adding a "recipes" section or something to the docs, for e.g. react and other common frameworks. Might be something someone could countribute :)

from parcel.

jakoblind avatar jakoblind commented on May 3, 2024 3

I wrote a guide on how to create a minimal React app using Parcel.

from parcel.

davidnagli avatar davidnagli commented on May 3, 2024 2

@thejameskyle How does this issue have anything to do with #15??? They are completely different issues!!!

from parcel.

devongovett avatar devongovett commented on May 3, 2024 1

Nice work @albinotonnina! Want to write up a small tutorial for the Parcel website with some code and explanations? The pages are just markdown files here: https://github.com/parcel-bundler/website.

from parcel.

jamiebuilds avatar jamiebuilds commented on May 3, 2024 1

It was a typo, calm down.

-> parcel-bundler/website#15

from parcel.

matheussampaio avatar matheussampaio commented on May 3, 2024

It's possible to use jsx? How?

from parcel.

NullVoxPopuli avatar NullVoxPopuli commented on May 3, 2024

this is my existing .babelrc

{
  "presets": [
    "env",
    "stage-0",
    "react",
  ],
  "plugins": [
    "transform-decorators-legacy",
    "transform-runtime"
  ],
  "env": {
    "production": {
      "plugins": [
        ["babel-plugin-remove-attribute", {
          "attribute": "data-test",
        }]
      ]
    }
  }
}

:-\

from parcel.

wemyss avatar wemyss commented on May 3, 2024

Is there an examples repo/document somewhere to put examples so new starters can find them easily / understand what is needed to get parcel to work in their stack?

from parcel.

matheussampaio avatar matheussampaio commented on May 3, 2024

Hot reloading would be neat! 😄

from parcel.

albinotonnina avatar albinotonnina commented on May 3, 2024

This is my first test with Parcel, React and hot-reload altogether:
https://github.com/albinotonnina/hot-parcel-react
It's based on the example @mjackson linked that for me didn't work. Component would get unmounted, not preserving the state, at every change.

I am not so sure about what I did here, because:

  • Didn't need any module.hot method
  • Actual Hot reload only after first save on a file. First time I get the component unmounted.
  • I needed to add require('react-hot-loader/patch') at the first line of the app because of a warning from react hot loader:

React Hot Loader: It appears that "react-hot-loader/patch" did not run immediately before the app started. Make sure that it runs before any other code. For example, if you use Webpack, you can add "react-hot-loader/patch" as the very first item to the "entry" array in its config. Alternatively, you can add require("react-hot-loader/patch") as the very first line in the application code, before any other imports.

I may have messed a bit with it.
Anyway, great stuff @devongovett

from parcel.

albinotonnina avatar albinotonnina commented on May 3, 2024

@devongovett I would like to. My solution smells a bit though! Let me see if I can do better

from parcel.

NullVoxPopuli avatar NullVoxPopuli commented on May 3, 2024

I think I found the root of my problem.
This project imports css into js... which, not sure if parcel should support that, cause I think it's a stupid pattern. :-\

some errors I've gotten:
image
after commenting all the styles out:

image

another caveat I found is that all pathing is apparently relative to the dist directory -- rather than relative to the index.html -- kinda weird.

from parcel.

davidnagli avatar davidnagli commented on May 3, 2024

@webular is having the same issue in #56… his example looks a lot more minimal

from parcel.

davidnagli avatar davidnagli commented on May 3, 2024

I figured out why @NullVoxPopuli is getting this bug!!! The .babelrc he’s using has a syntax error…

It’s not a problem with Parcel

There are 2 trailing commas which cause JSON.parse() to throw an error:

{
  "presets": [
    "env",
    "stage-0",
    “react” ,<—————HERE (unnecessary comma)
  ],
  "plugins": [
    "transform-decorators-legacy",
    "transform-runtime"
  ],
  "env": {
    "production": {
      "plugins": [
        ["babel-plugin-remove-attribute", {
          “attribute”: “data-test” ,<—————HERE (unnecessary comma)
        }]
      ]
    }
  }
}

Here’s the corrected version:

{
	"presets": [
		"env",
		"stage-0",
		"react"
	],
	"plugins": [
		"transform-decorators-legacy",
		"transform-runtime"
	],
	"env": {
		"production": {
			"plugins": [
				["babel-plugin-remove-attribute", {
					"attribute": "data-test"
				}]
			]
		}
	}
}

Try to use the corrected .babelrc above, and see if the error goes away

from parcel.

davidnagli avatar davidnagli commented on May 3, 2024

We need to add a try/catch around the JSON.parse() in /src/utils/config.js:35:17 to through a better error whenever we encounter a syntax error with the users .babelrc

from parcel.

devongovett avatar devongovett commented on May 3, 2024

@jakoblind nice work! Want to make a PR to https://github.com/parcel-bundler/website with that guide?

Would be nice to have an additional section about setting up hot module reloading with react-hot-loader as well.

from parcel.

albinotonnina avatar albinotonnina commented on May 3, 2024

@devongovett should I put my solution? Would you have a look at it again?
#19 (comment)

from parcel.

jamiebuilds avatar jamiebuilds commented on May 3, 2024

Moving to #15

from parcel.

davidnagli avatar davidnagli commented on May 3, 2024

oh haha, that explains it...

from parcel.

yamitzky avatar yamitzky commented on May 3, 2024

@davidnagli .babelrc accepts JSON5, so I think trailing comma is not a syntax error. parcel fails if JSON5-flavored .babelrc exists in node_modules.

from parcel.

yamitzky avatar yamitzky commented on May 3, 2024

I made a PR to handle JSON5 #256

from parcel.

Related Issues (20)

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.