Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for setting default scripts-version from template.json #8335

Open
jamesknelson opened this issue Jan 18, 2020 · 1 comment
Open

Support for setting default scripts-version from template.json #8335

jamesknelson opened this issue Jan 18, 2020 · 1 comment

Comments

@jamesknelson
Copy link
Contributor

Is your proposal related to a problem?

I've been maintaining universal-react-scripts, a version of react-scripts which includes SSR support. I've recently been trying to merge in the changes from 3.3.0, but as it stands, it would now require that instead of just asking the user to specify --scripts-version with CRA, they'll also need to specify the --template option.

The reason for this change is that universal-react-scripts was already applying some changes to the template within its init script, with the files stored next to the existing template directories. However, with 3.3.0, the template could be anything -- so it's no longer possible to apply this transformation. Instead, the user will need to specify an SSR template from the start.

Describe the solution you'd like

For something like SSR, the template and scripts version need to work together. To facilitate this, I propose that we add support for a defaultScriptsVersion property to template.json. Then, the create-react-app script should:

  1. Install and unpack the template to get access to template.json.
  2. Check for a defaultScriptsVersion, falling back to react-scripts as the default.
  3. Then install the scripts and other packages as before.

Describe alternatives you've considered

The obvious alternative is to ask people to pass compatible --scripts-version and --template options to create-react-app:

npx create-react-app --scripts-version=universal-react-scripts --template=universal

This is pretty verbose though, and will break if only one of the two options are passed. Ideally, the user could just do this:

npx create-react-app --template=universal

Another alternative would be to somehow allow the scripts version to transform the template name. This has the advantage of allowing the scripts to bail on unsupported templates -- but it sounds far more complicated.

@jamesknelson jamesknelson changed the title Support for setting deafult scripts-version from template.json Support for setting default scripts-version from template.json Jan 18, 2020
@jamesknelson
Copy link
Contributor Author

I should add that I'd be happy to put a PR together if there's agreement that this would make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant