GithubHelp home page GithubHelp logo

General feedback about create-react-app HOT 152 CLOSED

facebook avatar facebook commented on April 19, 2024
General feedback

from create-react-app.

Comments (152)

gaearon avatar gaearon commented on April 19, 2024 8

Also, I ejected pretty soon. Why not just eject right away? - I did not see any advantage of using the un-ejected version. The tool is already creating some boilerplate for me, it might as well create more.

The number one complaint I heard about “JavaScript fatigue” is that there are tons of dependencies in package.json and you aren’t sure how/when to update them because they are often incompatible, each requires maintaining its own config, releases breaking changes, etc.

https://twitter.com/thomasfuchs/status/708675139253174273

Here is a good example of an issue like this. Somebody was trying to follow a “React for Beginners” starter guide but updated Babel and got a weird error: babel/babel-loader#255. If you hunt around, you’ll find hundreds of issues like this across different boilerplate projects, React, Redux, Babel, ESLint, etc.

If you’re comfortable configuring ESLint, Babel, and Webpack yourself, you can indeed eject right away. This is the level of utility already provided by the popular boilerplate projects. However, if you’re not used to those tools, having a bunch of complicated configs in your folder is very intimidating. I’m trying to provide a better experience for people who are just getting started with React and don’t want to customize anything—rather, they want somebody to hold their hand while they’re writing their first component. And providing the escape hatch turns it from a toy into a real tool.

Another intention is that we keep improving the default set of plugins over time. For example, we might switch to Webpack 2, or Babel 7, or ESLint 3, or whatever, at our own pace, at the same time ensuring they all work great together. This is something a user can’t easily do if they’re on their own unless they have an extensive knowledge of all those tools.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 7

@gaearon I know you mentioned not wanting to have the user configure anything, so I am thinking more of an implicit kind of thing.

While it might not be totally pragmatic to hide the index.html file, it might make sense to just let the user know that they need to create a Main.js file in the root of their app. (similar to something like Elm).

Isn't this what we do? The location and names of index.html and src/index.js are conventional, you can't change them. The HTML file was added because people really want to customize it (for example meta tags or google analytics) but it doesn't let users change anything related to bundling.

I was about to ask you if we want multiple scaffolds/boilerplates, but I'm not sure if that aligns with the design decision here

To me, this is an explicit non-goal. People have attempted to do this, but this creates a combinatorial explosion of different incompatible tools and approaches. Beginners won't know what to choose, and advanced users will be frustrated there is not enough choice.

My motivation behind this is, CSS Modules is popularly adopted and a lot of people would want to use it in their project.

Are they good enough and easy enough to explain that we can make them a default for everyone? Every other single tool that we use, in my opinion, passes this test, but CSS Modules, as much as I like them, don't yet, in my opinion.

This is why we don't include them, and this is our philosophy in general. If we can't recommend something to everyone using React, or at least consider it a sane default while keeping in mind that for many people this is the first exposure to React, we don't add it.

Perhaps in a year CSS Modules will be obvious to everyone and we will get many requests from beginners to support them. Then we ship a codemod as yet another script that ports everyone's projects to use CSS Modules, and they become our default recommendation. I totally see this happening but not today. We need to pick our battles.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 7

I think our guideline should be: let’s ship ESLint warnings that help find bugs or avoid bugs in the future.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 7

There is a space for more than a single tool.
Let’s keep learning from each other’s work!

from create-react-app.

insin avatar insin commented on April 19, 2024 5

Likely first issues:

"Where's the hot reloading?"

One of the issues opened on the same day reactpack was posted on Show HN was related to not using the default ESLint presets they chose - how easy is it to disable it or use your own with the current setup? Code style can be a controversial topic, even if people have specifically asked for more opinions.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 5

In my experience linting catches many mistakes. Beginners who are just getting started often don’t bother to configure a linter, and suffer from errors caused by simple typos.

Having control over linting also gives us the ability to introduce custom rules and potentially add API deprecations.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 4

If the project doesn’t crash, those warnings also show up in the console:

screen shot 2016-07-18 at 13 57 31

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 4

My intention was to bootstrap a project that shows:

  • How to create a component
  • How to import a component from another component
  • How to reference CSS
  • How to reference an image
  • How to render the root component to the DOM

Those are the most common questions I see about Webpack-based setups, and it is not obvious at all that you need to import CSS until you see it. So I think it’s important to explain it to people who never worked with Webpack.

If we don’t provide these, people will try adding images in local directory and expecting them to be available by paths like src='./logo.png', they will add CSS to index.html without realizing we already solve autoprefixing for them, and they will import components with named imports (import { App } from './App') while using default exports and be frustrated that this doesn’t work.

How do you think we could solve those problems without frustrating experienced users?

from create-react-app.

kasperpeulen avatar kasperpeulen commented on April 19, 2024 4

I think there is a real need for a project like this. I would keep the configuration as minimal as possible. One good reason, there doesn't exist much (or any) project like this. Maybe someone else makes some other starter project with more config options, but I think there should be a place in the javascript ecosystem for a minimal config tool like this.

I'm learning javascript for a couple of weeks, and I'm trying to write a project in ES2015/ES2016 + react, mainly for learning.

In this process of learning, I notice that I'm 75% learning about tools, and 25% learning about actual code and writing code. When I was learning iOS in Swift, this is what much different. I think 10% was about tools, but I felt productive right from the beginning, just coding and coding. Now I'm reading manuals about webpack, babel, autoprefixer, eslint, flow, live reloading etc. etc..

I know it is all helpful, because I love writing code in ES6 syntax, and I love catching errors at compile time. I love seeing my css changes right in a second in the browser, but it takes a lot of time before I actually get to write some code.

Then with boilerplate, this helps somewhat, but I don't feel comfortable having a boilerplate where 90% of the code I don't understand what is going on. All kind of test frameworks (I haven't spend any time learning javascript test frameworks yet). Karma, Mocha, gulp, rollup, commonjs, umd, whatever, ugh ... my brain just overloaded with names ... names that doesn't say anything to me, and where I feel like I should still read more about

So yes, I used react-scripts for a couple of hours, this, and I love it, it is clean, all the code in my own package I understand, that just feels good. Okay, there is probably some magic going on that I don't understand, but that is fine. I don't understand how chrome makes my html and javascript turn into a webapp, but that is none of my business. That is chrome's business. I don't understand how react-scripts makes my ES6 code work, how it gives me compile time errors, how it imports my css using javascript import, or how it add autoprefixers to my css, but it just works. And all that is now facebook's business. I just care about how to use it. Not how they made it work.

So this is one use case for react-scripts/create-react-app, people that are learning web programming in 2016 and learning ES2015/2016 syntax right from the beginning. What this provides is way to immediately start with learning how to code and don't worry much about tools yourself.

🎶🎶🎶
Let's start coding now,
everybody is learning how,
come on and safari with me.
🎶🎶🎶

https://www.youtube.com/watch?v=IMChBJZUDK8

from create-react-app.

eanplatter avatar eanplatter commented on April 19, 2024 3

I guess they can always eject if they want to configure things themselves.

from create-react-app.

kentcdodds avatar kentcdodds commented on April 19, 2024 3

While you're at it, maybe you could add: "semi": [2, "never"] :trollface:
Sorry, someone had to say it. (But if that happened, I'd be pleased)

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 2

We might eventually add hot reloading when it is stable enough but I don't think it should be a part of the official starter if it's hacky right now.

I do expect some people to ask for custom lint configuration but I'd rather not do it. Give in just a little, and you'll end up with a lot of configuration. It will be hard to draw the line where to say "yes" and where to say "no". React has never been opinionated so I think we have a right to release one very opinionated tool.

from create-react-app.

lacker avatar lacker commented on April 19, 2024 2

Playing around, I find myself often deleting some of the autogenerated files, because I don't want some subset of App.js, App.css, index.css, logo.png. What do you think about simplifying the autogenerated stuff to just index.html and index.js in the main folder? (No src.) The pattern where you have your index files at the root and then other stuff is in a folder is how React Native typically works, for example. (E.g. https://github.com/fbsamples/f8app ) And that pattern seems fairly common for React apps too. E.g. https://github.com/reactjs/redux/tree/master/examples/todomvc That way people can decide if they want a "src" folder or what.

from create-react-app.

mxstbr avatar mxstbr commented on April 19, 2024 2

See the discussions in #13, #24 and #55, I don't think we want to go down the route and make this a react-cli.

from create-react-app.

kasperpeulen avatar kasperpeulen commented on April 19, 2024 2

I just wanted to say that I love love love love this 💃 👍 🍰 🎉

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 2

Thank you!
(By the way you didn't find this earlier because we released it a few hours ago)

from create-react-app.

Ethanjfriedman avatar Ethanjfriedman commented on April 19, 2024 2

As an instructor at a web dev bootcamp, just wanted to say this is great. 👍

The config swamp was a real hurdle for budding junior devs to get over in learning React -- understanding JSX, lifecycle methods, organizing their code into modules, etc. etc. is hard enough for someone with 2 months of coding under their belt without adding in messing around with Webpack and Babel. which topics we can layer in later.

from create-react-app.

aweary avatar aweary commented on April 19, 2024 2

It'd be interesting if there was a potential extension/plugin system for creating apps with more specific use cases. Being able to do create-react-app --with-router or create-react-app --relay would be useful. Maintaining or supporting that kind of configurability might be difficult though, so an extension system where anyone could plug into the app build step and introduce dependencies/files/configuration would nice.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 1

We definitely want to support n / nvm.

from create-react-app.

mxstbr avatar mxstbr commented on April 19, 2024 1

It's a nicer dev experience, and the react community is pretty set on using airbnb. Imo that's fine!

from create-react-app.

lacker avatar lacker commented on April 19, 2024 1

To be honest I would rather choose our own subset of rules that is more flexible about code style than remove linting altogether from the flow.

Mmm that sounds good to me. I tried using the airbnb style on a sample app and found it was too strict for what I wanted - in particular I ended up disabling

"rules": { "arrow-body-style": 0, "new-cap": 0, "no-console": 0, "no-param-reassign": 0, "no-undef": 0, "no-useless-constructor": 0, "no-use-before-define": 0, "react/prefer-stateless-function": 0, },

Like, if we tell noobs they shouldn't use console.log, they will become sad.

I really like the idea that we can update these tools over time and thus not become dependent on eslint specifically.

Also I think it would be nice to try to use similar language presets for the default apps created by React and React Native - it'll just make it easier for anyone building or documenting a cross-environment library.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 1

FWIW I’m not completely opposed to CLI flags. create-react-app my-app --template empty is fine in my book because this lets us add more official examples later to get people started with something they can run and tweak.

from create-react-app.

lacker avatar lacker commented on April 19, 2024 1

So I am actually one of these webpack noobs, I haven't forgotten what it's like ;-)

Before using this tool I never included css and images with an import statement the way it works here. I'll admit it was helpful. I didn't realize there was "autoprefixing" going on, though. How exactly does that work? Is it just using the stuff in https://github.com/postcss/autoprefixer ? Perhaps just a brief comment explaining that would be helpful somewhere in the code.

Also, it was unclear to me whether the "src" directory is special in some way. I have used some webpack configs where you have to put everything in a certain directory, and some where it does not work that way. Is there any requirement besides the starting point being src/index.js? Like do other image / css files have to also be in the src directory? Personally I often prefer to not call the directory "src" because if you e.g. end up making a rails backend, your ruby code is also "src" and so it's confusing to call just one of your languages "src". Or for React Native.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 1

Before using this tool I never included css and images with an import statement the way it works here. I'll admit it was helpful. I didn't realize there was "autoprefixing" going on, though. How exactly does that work? Is it just using the stuff in https://github.com/postcss/autoprefixer ? Perhaps just a brief comment explaining that would be helpful somewhere in the code.

I think we need a “How To” document. It would explain the available features: ES modules, importing CSS, autoprefixing. It doesn’t need to be long, just needs to answer 10 common questions in a practical way.

Is there any requirement besides the starting point being src/index.js?

Having index.html and src/index.js is the only requirement. (Ideally we should check for their existence and crash with a descriptive message if either was not found.)

Like do other image / css files have to also be in the src directory?

All modules have to be there, src is where the code of your application is. We may want to introduce other top-level folders later, e.g. vendor for third party assets you want to reference directly from .html. This would be an escape hatch for scripts that aren’t on npm for some reason. We wouldn’t want webpack to look at those, so having a folder just for modules is useful.

Personally I often prefer to not call the directory "src" because if you e.g. end up making a rails backend, your ruby code is also "src" and so it's confusing to call just one of your languages "src". Or for React Native.

React Native is a very special case. I would probably go into direction of sharing code with React Native, so you’d still put your modules into src but “fork” components with build time flags. Other top-level directories could be used for RN-specific purposes (e.g. Xcode project). But I’m not very aware of RN project structure.

I don’t exclude that one day this will be ready to work with RN out of the box. We can rethink directory structure on that day, when we understand the constraints a little better.

As for Rails or Node, my intention is for the client to be treated as a separate “app” from its backend. So I would assume something like this:

my-awesome-app
  backend
    src
    config
    tasks
    email-templates
  frontend
    src
    vendor
    whatever

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 1

Assuming the first release is an opinionated starter, is a longer-term goal is to become the react-cli people keep asking for?

It is hard to say. I definitely don't want any plugin system (which is what Ember CLI is famous for). The intention is to free user from configuration and incompatibilities. It we replace this with another configuration system or another addon system with its own issues, we defeat the point. (No offense to Ember.)

What you describe sounds ambitious but it is very hard to pull off. I want to start small and see how it goes.

I don't think code generators are as valuable as people say they are. If you need to generate code it means your libraries aren't expressive enough. Stuff like "add new component" — what's wrong with just writing a function by hand? The only frustrating thing is remembering to import React when you use JSX but this would better be solved on the IDE level or with an "autofix" system.

I am definitely interested in "initial" templates as described in #24. They are not as flexible as code generators but are much less pain to maintain and create. These are just "examples" of integration with libraries.

So we will see how it goes. It's hard to say in advance. For now we want to solve the build configuration problem. If it is adequately solved, we can consider solving other problems (such as integrating runtime libraries) but we need to be careful not to inflate the scope of the project too much.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 1

Redux is not a default way of using React. Quite the opposite, it is a very opinionated way of using it.
So we definitely won’t include any code generation for reducers / action creators / etc here.
We should improve React instead to address the shortcomings that make people go for Redux.

from create-react-app.

mxstbr avatar mxstbr commented on April 19, 2024 1

Didn't mean to imply those generators should live here, sorry!

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 1

I wouldn’t say it’s forever out of scope but definitely not this year. 😄

from create-react-app.

kirkaustin avatar kirkaustin commented on April 19, 2024 1

I think it's great that you're providing a less opinionated baseline for the configs, as I was never that comfortable with the airbnb solution. It might be worth considering allowing for some overrides, though. That way I could just add a small number of eslint rules that would be concatenated with your defaults if I wanted to customize.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024 1

@aweary Please see #24

from create-react-app.

KarolAltamirano avatar KarolAltamirano commented on April 19, 2024 1

Awesome project guys, thanks for creating it. I have one question about the project structure. Wouldn't it be better to have index.html and favicon.ico inside src folder? I would personally prefer to have all react app files including index.html and favicon.ico inside src folder and directly in the root folder just files / folders related to dev process even though it will be just node_modules, package.json and README.md

from create-react-app.

KarolAltamirano avatar KarolAltamirano commented on April 19, 2024 1

@mxstbr @PhilipGarnero Yep, it depends on point of view and from both sides it can make sense. The reason why I prefer to have everything app related in the src folder is that when I start adding files like .gitignore, .gitattributes, .editorconfig to the root folder it will just feel a bit messy to me to have somewhere between these files also index.html and favicon.ico

Anyway I got your point about webpack modules and if you think it works better the way it is right now I'm okay with it. Just wanna share my point of view on structuring projects even though it's more about personal preference than an actual issue.

from create-react-app.

mxstbr avatar mxstbr commented on April 19, 2024 1

A .gitignore file will automatically be created with the new version. 👍

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

cc @insin @mxstbr @eanplatter @ericclemmons, thank you so much for your time & ideas

from create-react-app.

ericclemmons avatar ericclemmons commented on April 19, 2024

Should we encourage or support something like nvm? Or will we specify a minimum version of Node that we can test against to ensure consistent behavior/performance?

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

I'd add node >= 4 to engines. The CLI script actually already checks against this field (we took it from RN).

from create-react-app.

eanplatter avatar eanplatter commented on April 19, 2024

I'd be interested to hear what people thought about eliminating 100% of the boilerplate code. We tried to do this we enclave but made up for it with a small amount of configuration. (telling enclave where to find the index.html / React entry point).

@gaearon I know you mentioned not wanting to have the user configure anything, so I am thinking more of an implicit kind of thing.

While it might not be totally pragmatic to hide the index.html file, it might make sense to just let the user know that they need to create a Main.js file in the root of their app. (similar to something like Elm).

While boilerplate is a helpful way to show a new user how to get started, it can be hard for beginners to know what they can touch.

Also, sometimes when a user is using something with boilerplate, it can make community resources (like tutorials) a bit harder to grok because they're having to dance around code written by the tool.

I'm willing to be swayed either way :P but in my experience I've found that beginners appreciate the ability to understand all the code written in their application.

from create-react-app.

keyz avatar keyz commented on April 19, 2024

I was about to ask you if we want multiple scaffolds/boilerplates, but I'm not sure if that aligns with the design decision here. Maintaining multiple scaffolds is also an overhead. As a solution, I thought about this a while ago and I imagined a npm init-like interactive cli initialization experience -- something like:

Do you want to use CSS Modules? (Y/n)

My motivation behind this is, CSS Modules is popularly adopted and a lot of people would want to use it in their project. But if I'll need to "graduate" in order to add the config, then it feels more like a yet-another boilerplate again. Do you think this fits with our design goal?

from create-react-app.

eanplatter avatar eanplatter commented on April 19, 2024

I do expect some people to ask for custom lint configuration but I'd rather not do it.

What is your thinking behind adding linting to begin with? It might make sense for it to be lint agnostic.

from create-react-app.

eanplatter avatar eanplatter commented on April 19, 2024

👍 is there a lint script in the users new project?

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

No, we do linting as part of both npm start and npm run build. It’s done via eslint-loader.

So the user sees something like this when they save a file:

screen shot 2016-07-18 at 13 56 25

from create-react-app.

lacker avatar lacker commented on April 19, 2024

I found the linting frustrating when I tried starting here and following along on other tutorials that don't follow the linting rules. Some of the rules like no-var and semi are in conflict with a lot of our own example code. What do you think about having lint hidden behind something like npm run lint?

In my experience of asking people, most folks do not use a linter. And most folks who say they use "airbnb lint" have actually customized it a bit.

from create-react-app.

lacker avatar lacker commented on April 19, 2024

So right after I ran create-react-app, it had a file:/// dependency in the package.json. Is that supposed to happen when this is live, or is that an artifact of running it from npm run create-react-app? If it actually creates a project with a dependency on the creation tool which lives outside the repo, then I can't collaborate with other people on it.

from create-react-app.

lacker avatar lacker commented on April 19, 2024

Also, I ejected pretty soon. Why not just eject right away? - I did not see any advantage of using the un-ejected version. The tool is already creating some boilerplate for me, it might as well create more.

from create-react-app.

lacker avatar lacker commented on April 19, 2024

Also, how about rendering to a specific element rather than doing const rootEl = document.createElement('div'); document.body.appendChild(rootEl); render(<App />, rootEl);

That way you don't need to muck around with js code if you need to do something like add some custom html to your app.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

So right after I ran create-react-app, it had a file:/// dependency in the package.json. Is that supposed to happen when this is live, or is that an artifact of running it from npm run create-react-app? If it actually creates a project with a dependency on the creation tool which lives outside the repo, then I can't collaborate with other people on it.

No, this is because packages are not on npm yet.
In the “normal” npm flow, you’d get a regular dependency.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

Also, how about rendering to a specific element rather than doing const rootEl = document.createElement('div'); document.body.appendChild(rootEl); render(, rootEl);

That way you don't need to muck around with js code if you need to do something like add some custom html to your app.

I’m not sure what you mean. What kind of custom HTML? Why not do it in a React component instead? To be clear, this tool is targeted towards people creating greenfield single-page apps. React already has a good integration story; we just want to fix the “start from scratch” story.

We can change it for sure, but I’d like to better understand the use case you have in mind.

from create-react-app.

lacker avatar lacker commented on April 19, 2024

I was thinking adding other libraries like analytics, where you often have noobs following some instructions of how to modify their html. It's a bit simpler to figure out what's happening if there is a div already in index.html that your app gets rendered to.

from create-react-app.

lacker avatar lacker commented on April 19, 2024

Another intention is that we keep improving the default set of plugins over time. For example, we might switch to Webpack 2, or Babel 7, or ESLint 3, or whatever, at our own pace, at the same time ensuring they all work great together.

So the idea is that someone would be able to just upgrade their create-react-app-scripts dependency, and then they could get more modern stuff? That seems cool. If you can't upgrade this set of scripts, though, then it seems equivalent to saying "heres some boilerplate, just never update it".

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

I found the linting frustrating when I tried starting here and following along on other tutorials that don't follow the linting rules. Some of the rules like no-var and semi are in conflict with a lot of our own example code. What do you think about having lint hidden behind something like npm run lint?

To be honest I would rather choose our own subset of rules that is more flexible about code style than remove linting altogether from the flow. In my experience of replying to issues on React and Redux repo, people often do mistakes that would be caught by a linter. A separate npm run lint wouldn’t help them because they wouldn’t run it.

In my experience of asking people, most folks do not use a linter. And most folks who say they use "airbnb lint" have actually customized it a bit.

I think there is a middle ground here: beginners and people who didn’t bother to use a linter because it is too complicated to set it up (e.g. ESLint didn’t work with ES6 until recently, babel-eslint integration was often buggy while it was necessary, etc).

Maybe my bet is off. I don’t know. But I feel like it’s better to start enforcing the lint, and later loosen it up, than start relaxed and later tighten it up. We can teach people that it is an opinionated tool, and this is what we think is the best way to start getting up to speed with React.

We use vars in the docs because our docs assume ES5. This is a different and separate issue: we do intend to update them, but we need a plausible “getting started” experience that includes ES6 for this. So it’s a bit of a chicken-and-egg problem.

I was thinking adding other libraries like analytics, where you often have noobs following some instructions of how to modify their html. It's a bit simpler to figure out what's happening if there is a div already in index.html that your app gets rendered to.

Perhaps. I thought the comment in index.html helps, does it not?

So the idea is that someone would be able to just upgrade their create-react-app-scripts dependency, and then they could get more modern stuff? That seems cool. If you can't upgrade this set of scripts, though, then it seems equivalent to saying "heres some boilerplate, just never update it".

Yes, the idea is that we release versions once in a while that track what’s going on in the ecosystem and put the best stable things together.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

Would you like to send a PR with the ESLint rule subset you find reasonable?

from create-react-app.

lacker avatar lacker commented on April 19, 2024

Sure - not fair of me to gripe without offering to fix it ;-)

from create-react-app.

vjeux avatar vjeux commented on April 19, 2024

I was going to say, we already have Facebook eslintrc on fbjs but it seems like every single of our open source project is using a different variation:

from create-react-app.

eanplatter avatar eanplatter commented on April 19, 2024

I can't help but agree, it's easy to forget how valuable it is to see first hand how to do something like reference a CSS file in a React component.

Keeping the boilerplate as minimal as possible (like it currently is) is important. Perhaps some inline comments to help dispel any questions about the generates code itself?

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

Let’s continue this discussion (on templates) in #24.

from create-react-app.

insin avatar insin commented on April 19, 2024

Do you have a longer-term scope in mind?

Assuming the first release is an opinionated starter, is a longer-term goal is to become the react-cli people keep asking for?

What I'd really like to see is something which handles the core development setup (and owns configuring the DX adds like HMR, auto-install) and can install opinionated project setups which build on top of that with their own configuration, starting you out from a skeleton, providing generators for whichever opinions it has, with codemods to keep code up to date as things evolve. It would also need to be configurable on top of that default where the opinions can be flexible.

The goal would be that the core development setup and opinionated project setup mean upgrading when dependencies change is just bumping a version number, with codemods when you need them as long as you've stuck with the opinions.

The way react-project provided glue code as a dependency rather than boilerplate was also really interesting to me.

from create-react-app.

insin avatar insin commented on April 19, 2024

I definitely don't want any plugin system (which is what Ember CLI is famous for)

I don't think React even needs that in the same way Ember does - once Webpack is set up right, you just import and go instead of having to make stuff available to a template context. Largely the same thing with testing; once your tools are set up right, the actual tests are just import and use.

Stuff like "add new component" — what's wrong with just writing a function by hand?

I agree on generators for trivial things, I'm thinking more of when you have some conventions which are working for you, you need to do something which cuts across multiple modules and dependencies and you'd like to make it reusable across multiple projects. For example if I were to write an add section <path> <name> generator for the conventions I'm using in my main React project at work right now, it would:

  • Create src/routes/<path>/<name>.js, generating a component with a render() which will add <name> to the page title
  • Add a new <Route> definition to the appropriate place in src/routes/root.js which will code split the route component (so far, so Ember)
  • Going further, possibly have a few prompts:
    • "Does this section need a reducer?" - if so, take a name, create src/reducers/<name>.js as a duck module with the same layout as our other reducers, and also configure loading and injecting this reducer when the route first loads (and handling hot reloading setup), and create a suitable unit test skeleton.
    • "Does this section need a feature flag?" - (configure all the different places that needs to happen)
    • "Will this section appear on the main Navbar"? - (configure all the different places that needs to happen, including whether or not it's feature flagged)

Something like the above is a lot of work, but it mostly happens outside the global CLI and the module which solves the base build configuration problem, and it needs a way to hook into them or be hooked into by them. Just raising it now as the current template this project has is exactly as it should be IMO - here's your first component, the build stuff is handled for you, let rip - so it doesn't need these hooks.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

I think most of these points should be solved on the library level, not code generation level.
For example:

Add a new definition to the appropriate place in src/routes/root.js which will code split the route component (so far, so Ember)

This is a problem with having global configuration. Imagine React Router worked in a different “100% React” way and nested routes would be implemented as nested components, without centralized config. Then this wouldn’t be an issue because you’d just add a new route right in the component you are working on. (Something like this may or may not be in development right now—not by us though. I won’t spoil it further. 😉 )

"Does this section need a reducer?" - if so, take a name, create src/reducers/.js as a duck module with the same layout as our other reducers, and also configure loading and injecting this reducer when the route first loads (and handling hot reloading setup), and create a suitable unit test skeleton.

Again, this seems like a problem with React state model. Ideally I think we should make React more reducer-friendly so that it’s easy to describe local state with a reducer, and move a reducer across the components. Then you wouldn’t have to jump between the files.

To be clear, I’m not saying what you suggest is not valid. Somebody could implement a generator like this as another devDependency, and maybe we’d want to merge it in eventually. But I think the need for code generation is usually symptomatic of abstractions that are not expressive enough, and we might want to fix that instead.

from create-react-app.

mxstbr avatar mxstbr commented on April 19, 2024

That's exactly what we do for our react-boilerplate generators – e.g. when you generate a container, it adds a bunch of files:

index.js     # Component itself, can either be function or class
actions.js
constants.js
reducer.js
test/        # The tests for all of those
  actions.test.js
  reducer.test.js
  component.test.js

Doing this manually every time is quite tedious, so having that automated and pre-populated with the correct data saves quite a bit of time!

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

That said nothing prevents somebody from creating react-redux-generator that would be another devDependency and generate this stuff.

from create-react-app.

eanplatter avatar eanplatter commented on April 19, 2024

Code generation can also fuel misinformation, it makes it easy for a user to be ignorant of the code in their app, this is especially an issue for beginners.

I think the need for code generation is usually symptomatic of abstractions that are not expressive enough, and we might want to fix that instead.

This is kind of the crux of it ☝️

If there are issues with React's usability we don't want to sweep them under the rug by just writing the code for you.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

Haha no offence taken. 😄

from create-react-app.

montogeek avatar montogeek commented on April 19, 2024

What would be the testing library? Enzyme is a nice candidate :)

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

Eventually, yes, but this will need more thought.

from create-react-app.

SpencerCDixon avatar SpencerCDixon commented on April 19, 2024

Are there any plans to eventually provide an "addon" abstraction like ember-cli has so that developers can build a community around the CLI or is that out of scope/not something this project should be concerned about?

from create-react-app.

eanplatter avatar eanplatter commented on April 19, 2024

There's been a little discussion on it here: #24

from create-react-app.

roebuk avatar roebuk commented on April 19, 2024

First off, this is a great project, thank you for creating it.

Would it be worth outputting a webpack-stats.json file for ease of grabbing the built assets by other systems?

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

@roebuk This sounds like a useful feature but we want to limit the ways we expose webpack so we could potentially replace it in the future. I’m not totally opposed to this though, especially if there was a more widely accepted simpler standard format for this.

from create-react-app.

PhilipGarnero avatar PhilipGarnero commented on April 19, 2024

You guys are awesome ! I started react 3 days ago. I am really upset I didn't find this earlier. So much headaches and pointless questions would have been avoided.

This is very helpful ! Especially the readme. It would have saved me so much time if I read it when I begun. Keep improving it.

Keep your mind on newcomers, they'll be more than happy with what you provide.

The only thing is that I find a bit weird that the index.html and favicon.ico files are not inside src. I would have expected the root dir to be free of any sources or resources and only have conf files. But that's just me.

from create-react-app.

a-tarasyuk avatar a-tarasyuk commented on April 19, 2024

It is good starting point in standardization all react-boilerplate's. Thanks. I think would be very useful to have opportunity extend/override configs,. for instance for webpack, babel, eslint, and so on. I think community should discuss all features which this tool should have, and create good style guide.In my opinion we should have lightweight/extendable tool based on style guide, and extend it for own purposes

from create-react-app.

pirelenito avatar pirelenito commented on April 19, 2024

Interesting approach.

However I'm not sure it is a solution for the problem it is trying to fix. The way I see it, it is merely delaying it. As pointed by this thread, it will be much sooner than later that any project will require some minimum configuration, which will lead to an eject and the user is back to the "JavaScript fatigue" situation:

  • lot of files and configurations that are impossible to grasp;
  • very hard to keep the build system updated and with new fixes/improvements.

I think the problem we should try to solve are more geared towards "good configurable defaults". We sure can hide all the complexity of configuring tools behind a single dependency, but we must allow a level of configurability with formal escape hatches to disable and extend the default configuration.

Such approach does come with some drawbacks, as you will get more mileage if you stick to the proposed conventions (like the linting and the test tool), but once we look over the bike-shedding, the end result in a tool that just works.

And as has already been said in this thread, the point of such tools is not to provide a high level of customization, if you need so, you can use the underlying tools directly.

This is what I've been trying to solve in the past couple of months in a tool that I've iterated a couple of times already called Sagui. It is a single development dependency that is auto-bootstrapped (no global CLI) and provides all the requirements to build a modern JavaScript front-end application with Build, Optimization, Development Server with Hot reloading (with React support), Test, Coverage and more!

More importantly, it is already used in a couple of projects in production.

And the developers have the benefit of the continuous improvement of their working environment with a single npm install.

Would love to hear you thought on it as well, as I deeply respect your opinions! ❤️

tl;dr:

  • We can't run away from configurability: embrace good defaults but provide formal escape hatches;
  • Should be easily upgradeable: users can get constant improvements, like build speed, usability tweaks and bug fixes by just updating the dependency.
  • Reduce context overhead and leverage npm scripts: try not to introduce another global tool;
  • Don't try to create another plugin ecosystem: we already have Babel, Webpack and Karma;

@mxstbr: Your work on react-boilerplate has helped us a lot on building Sagui :)

@gaearon: You helped shape the current version of Sagui after a chat we have in React Europe, so thank you!

from create-react-app.

PhilipGarnero avatar PhilipGarnero commented on April 19, 2024

@pirelenito you should maybe try to be the next step after create react app. I'm pretty sure you could work something out with @gaearon to create a tool to migrate his tool to yours like eject but more like an upgrade.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

I think would be very useful to have opportunity easy extend/override configs,. for instance for webpack, babel, eslint, and so on.

Please see my reply in #99 (comment).

from create-react-app.

pirelenito avatar pirelenito commented on April 19, 2024

Interestingly, I was planning to do the same thing at one point, but abandoned it favor of some simple configuration options and formal escape hatches. Maybe you will end-up on a similar situation?

What do you think is the major drawback of a tool such as Sagui?

Thanks!

from create-react-app.

kirkaustin avatar kirkaustin commented on April 19, 2024

Great project! Maintaining those configs is a real PITA. The only thing that's keeping me from embracing this is the lack of support for CSS Modules. I'm not sure I understand the objections, as it makes writing CSS rules much, much simpler for component-centric projects.

Also, I'd like more flexibility with the dev server. I'd like to add some proxy support to external web services using http-proxy, for instance.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

I'm not sure I understand the objections, as it makes writing CSS rules much, much simpler for component-centric projects.

Can you help me understand the problems they solve for you? Global class pollution, what else? Do you use composes?

from create-react-app.

tlrobinson avatar tlrobinson commented on April 19, 2024

Overall I love the idea of this project. I was sad @petehunt's rwb didn't seem to get much traction, so I'm glad to see a more official project with similar goals.

(Cross-posting the below from a HN comment. I haven't read through all the comments, apologies if this has been covered)

I think there will always be people who want to tweak ESLint rules or enable new Babel features, but would still like to take advantage of improvements to this project.

Perhaps exposing a subset of those tools' configuration options would be sufficient.

Alternatively, you could imagine a pretty simple system that allows you to pull newer versions of the "ejected" code and handle merge conflicts using your version control software.

I'd also suggest reducing the amount of non-configuration code that's generated by "eject". I think basically everything in "scripts" could be put into a package ("openChrome.applescript" seems like it should be a feature of opn anyway). That would also reduce the number of devDependencies that need to be added to your project's package.json (rimraf, chalk, opn, etc)

from create-react-app.

kirkaustin avatar kirkaustin commented on April 19, 2024

Global class pollution is the big win. Probably the best thing to happen to CSS since the beginning. Namespaces was one of the big wins when Java first appeared. I don't think anyone regrets that addition.

We have a few different groups writing reusable React components that can be shared. The problem of CSS collisions has led us down a path similar to BEM which requires verbose, nested class names.

The beauty of CSS Modules is that you not only avoid having to do that, but you end up using much simpler class names like ".icon" or ".content" which anyone can understand, not just engineers. We're trying to pull designers in the direction of using more CSS in the work that they provide, and we don't want to burden them with tools like SASS.

I haven't used composes myself, but it seems like it could be useful.

One other side benefit is that the development class names end up being verbose and easy to debug, while the production class names end up being very short and obfuscated.

from create-react-app.

keyz avatar keyz commented on April 19, 2024

@gaearon CSS Modules is awesome. I have an example here that might be able to show you how it works in action: https://github.com/keyanzhang/repo.cat/tree/master/src/components/Main/Filters/SingleFilter

In the CSS file I no longer need to "BEM" my CSS selectors. I can simply name a selector .link and it's guaranteed to be local to the component that imports it.

For example, let's say I have 2 components Foo and Bar. Both of them have a link that needs to be styled but the 2 links don't share the same style.

Without CSS Modules I could import './styles.css'; in each component file, but I'll need to give them different classNames like fooLink, barLink to avoid global name collision. This doesn't feel quite right to me since I need to mentally track all my components and make sure I don't accidentally use the same className for actually different things.

With CSS Modules, a class name gets renamed to something like SingleFilter__link automatically at compile time. It effectively solves the global namespace issue and enables me to think locally from a true component perspective.

http://glenmaddern.com/articles/css-modules is another great article that explains this concept.

from create-react-app.

mxstbr avatar mxstbr commented on April 19, 2024

It might be worth considering allowing for some overrides, though. That way I could just add a small number of eslint rules that would be concatenated with your defaults if I wanted to customize.

We've actually disabled all stylistic eslint rules, so there should be no need to add custom config. If there's a stylistic rule warning you're seeing please let us know immediately and we'll disable it with the next release. (see e.g. #157)

from create-react-app.

kirkaustin avatar kirkaustin commented on April 19, 2024

Well, my point is that I would like to add my own stylistic rules. That means I would like to append those rules to the ones that are provided.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

Thanks, we’ll keep this feature request in mind. Unlike Babel/webpack extensions, allowing custom eslint config seems fairly straightforward and shouldn’t hurt us in the long run (I can’t really imagine we’d have a compelling reason to move away from eslint). In fact creating a custom .eslintrc that extends our config at react-scripts/config/eslint could already work. We’re not going to generate such config by default, but I think we might document a way of doing this some time in the future.

from create-react-app.

kirkaustin avatar kirkaustin commented on April 19, 2024

Great, that's exactly what I had in mind.

from create-react-app.

idibidiart avatar idibidiart commented on April 19, 2024

@gaearon

What is Facebook's position on using Shadow DOMnfor CSS encapsulation? Have you seen Maples.js? https://github.com/Wildhoney/Maple.js/

Would you consider moving to this approach at some point? Or why not now? :-)

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

We are currently not planning to use Shadow DOM actively because it’s not supported by many our target browsers and requires global configuration. We may revisit this choice in the future.

from create-react-app.

mxstbr avatar mxstbr commented on April 19, 2024

src contains all files that webpack treats as modules, which index.html and favicon.ico don't count towards!

from create-react-app.

PhilipGarnero avatar PhilipGarnero commented on April 19, 2024

@KarolAltamirano @mxstbr Does it prevent it from working ?

If not, the users aren't handling webpack at all so I don't see the problem. Sure from your point of view, it seems silly but from mine, having these two files laying there feels kinda weird.

This is not an issue anyway and just a matter of preferences.
If you think it is more logical that way, you're probably right.

Thanks for your job on this project, I love it.

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

I would personally prefer to have all react app files including index.html and favicon.ico inside src folder

It depends on point of view. If you look at it another way, neither index.html nor favicon.ico are “React app parts”. React app starts in your root component, the rest can be thought of as host environment.

You could twist it either way though. So for now the distinction we chose is that src only contain modules (things that import each other), and anything else goes into the top level. We may revisit this later.

from create-react-app.

idibidiart avatar idibidiart commented on April 19, 2024

@gaearon

How do you approach style encapsulation for React components at Facebook? There is Radium which is for JS based style declaration and CSS Modules for creating isolated CSS scopes. Have you settled on a style encapsulation approach?

from create-react-app.

vjeux avatar vjeux commented on April 19, 2024

@idibidiart take a look at the first part of this talk (the one about cx), this is how we deal with styles at Facebook on the web today: https://speakerdeck.com/vjeux/react-css-in-js

from create-react-app.

mxstbr avatar mxstbr commented on April 19, 2024

@idibidiart also read #78 for a (long) discussion about this subject.

from create-react-app.

idibidiart avatar idibidiart commented on April 19, 2024

@mxstbr thank you for pointing me to that discussion.

@vjeux @gaearon there is a subtlety to why something like CSS Modules (+React CSS Modules) is preferable to our (my team's) way of building apps, and it is based on some axioms our team has developed over time that are not universal.

So, at this point we're considering creating a live fork of create-react-app to add support for those tools.

Eject is an escape hatch (exactly what the name implies), not a customization option per se.

I realize what I'm suggesting is not an optimal answer but it's as close to one as we could find right now. :-)

from create-react-app.

gaearon avatar gaearon commented on April 19, 2024

So, at this point we're considering creating a live fork of create-react-app to add support for those tools.

This is reasonable. (And we’ll keep an eye on popular forks.)

from create-react-app.

trevordmiller avatar trevordmiller commented on April 19, 2024

My 2 cents on the philosophy and future of this project

TL;DR

🤘 React Create App rocks! I hope to see this project continue to be wary of "design by committee" and stick to only the officially standard tools as you have been doing :)


Full thoughts

group-hug

I just want to give you all a great big hug :)

I absolutely ❤️ ❤️ ❤️ React Create App. It is extremely valuable to have a minimal abstraction for config so that the React team can optimize under the hood and tie all the pieces together without breaking the public API (npm start, npm build, npm run eject). Thank you so much for building it!

While reading through some of the comments on this page and on Twitter, I completely agree that this project should stick with minimal + majority use cases and not get too bloated; for example, I'm happy to see the push back that has already happened on things like CSS Modules, Radium, or other non "standard" tools. Unless an approach / tool is a "blessed" (officially supported) way of doing things by the React team, it shouldn't be included with this project. Getting too bloated has been the downfall of every other boilerplate generator / CLI I've used. I think react-create-app should draw a line in the sand that it will only concern itself with what it already has done - the compilation process - Webpack, Babel, ESLint (lint preventing build/runtime errors only). Unless the React team is going to officially bless an approach for linting, testing, styles, state management etc, then it would make sense to be incorporated. I am happy to see this is already what is being done - the React team has a fantastic track record of great wisdom and restraint in their feature requests!

from create-react-app.

trevordmiller avatar trevordmiller commented on April 19, 2024

My 2 cents on the customization problem

Obviously, people are going to have different needs for their projects; they can npm run eject but I think that ejecting should be viewed as a last resort because then your project loses the benefit of the config abstraction (access to continuous improvements, best practices, and updates from the CLI under the hood). I'd prefer to see react-create-app add a new feature for config composition of other configs to extend it's minimal out-of-the-box configs instead.

For example

The CLI could compose its configs with the user's package.json configs if it exists (ie if the eslintConfig property exists in the user's package.json, compose it with the react-create-app config). Same thing for the babel and webpack properties (might need to be a subset of setting properties).

from create-react-app.

trevordmiller avatar trevordmiller commented on April 19, 2024

My 2 cents on linting

I think including ESLint as has been done is the right move as it helps prevent errors; however, this is a fine line to walk as linting can also be used for style etc. The rules being used now seem to be good, but why not just use the "extends": ["eslint:recommended", "plugin:react/recommended"] options instead of manually maintaining a list of rules in react-create-app? The requirements for a rule to be added to this recommended list by the ESLint team seem to be in-line with what react-create-app is looking for: "
image

As for allowing users to customize these rules, see my composition proposal in the My 2 cents on the customization problem comment above ^.

cc: @nzakas

from create-react-app.

trevordmiller avatar trevordmiller commented on April 19, 2024

@gaearon Would love to hear your thoughts on my last three comments above if you get a chance ^ :)

from create-react-app.

PhilipGarnero avatar PhilipGarnero commented on April 19, 2024

Which procedure to follow when putting a project on git (or any other vcs) ?
By that I mean, should we upload node_modules ? (I'm new to the js env and it looks like not everyone is thinking the same way)

If not, what do we do when we clone the project ?
I didn't find anything about this subject yet. For now, it seems like the only solution is to create a new project and then override it with files coming from git. It doesn't seem really convenient.

A new command would be nice to have or even a create-react-app .

What are your thoughts about this ?

I'm more inclined to not putting node_modules inside the git repo as we do in the python community but this doesn't seem like a good practice with js devs.

from create-react-app.

lacker avatar lacker commented on April 19, 2024

@PhilipGarnero Don't upload node_modules to git. Instead, after cloning the project, run npm install immediately. I would recommend that workflow not just for create-react-app-based projects, but for any sort of version-controlled project using npm.

from create-react-app.

Lakston avatar Lakston commented on April 19, 2024

@PhilipGarnero I'll add to what @lacker said and recommend that you create a .gitignore file (either by hand or via github) and add node-modules to that file.

On github you can just click on add gitignore when creating your repo and chose node. You can also for exemple see my angular-twitch-viewer repo and copy/paste the gitignore file (it has a lot more than just node_modules).

from create-react-app.

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.