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

custom absolute path for npm build #778

Closed
adityashankert opened this issue Sep 27, 2016 · 6 comments · Fixed by #8986
Closed

custom absolute path for npm build #778

adityashankert opened this issue Sep 27, 2016 · 6 comments · Fixed by #8986

Comments

@adityashankert
Copy link

If I run npm build the build files are getting generated in the home directory of the project. Is there any way I can specify custom directory to generate build outside the home directory of the project?

Use case : I want to maintain build files and the development code in different repositories so that it will be easy for me to push to my CDN

@gaearon
Copy link
Contributor

gaearon commented Sep 27, 2016

There is no such option but you can work around it. Change build in your package.json scripts to perform an additional step, like react-scripts build && cp -r build ../your-folder. If you're on Windows the command would look differently but the idea is the same. There are also ways to write it in a cross platform way if you remove spaces before and after ampersands and launch a Node script that copies files instead of a UNIX command. I hope this helps!

@gaearon gaearon closed this as completed Sep 27, 2016
@adityashankert
Copy link
Author

adityashankert commented Sep 27, 2016

I guess this helps thanks :) but it would be great if we can pass configs to the script. Can we have it as feature request?

@gaearon
Copy link
Contributor

gaearon commented Sep 27, 2016

We generally don’t offer configuration options. Please see this document for more information.

This is intentional because it lets other tools integrate with Create React App more tightly because they can make assumptions about where sources and build output are. Since it is always possible to add this on top as an additional script, we don’t see the value in this being configurable, and it’s not worth the downsides in our opinion.

@gaearon gaearon reopened this Sep 27, 2016
@gaearon gaearon closed this as completed Sep 27, 2016
@gaearon
Copy link
Contributor

gaearon commented Sep 27, 2016

(Oops, didn’t mean to reopen. Fat finger.)

@ChuckkNorris
Copy link

ChuckkNorris commented Aug 26, 2017

@gaearon The biggest value for this type of configuration option is convenience - it's much easier to set a flag than it is to copy the files and delete the build directory, especially when that script is different between Mac and Windows.

You could always go the configuration file route similar to .angular-cli.json which would still enable other scripts to always know the build directory by reading that file.

For cross-platform dev:

"scripts": {
    "windows-build": "react-scripts build && xcopy /f /y build wwwroot",
    "mac-build": "react-scripts build && cp -r build ../wwwroot"
  }

Edit:
If you switch to use either Git Bash or Ubuntu Bash on Windows, the Unix commands work just fine:
Example which builds the react app, copies the contents from the /build folder to the /wwwroot directory and removes the build directory:

  "scripts": {
    "build": "react-scripts build && cp -r build/. wwwroot && rm -R build",
  }

@ZoranZilicFTN
Copy link

ZoranZilicFTN commented Feb 22, 2018

how would you write

  "scripts": {
    "build": "react-scripts build && cp -r build/. wwwroot && rm -R build",
  }

for Windows.

I tried with xcopy, but when I npm run build
where

  "scripts": {
        "build": " "react-scripts build && xcopy C:\FolderOne C:\FolderTwo",
  }

I get this error in the command line:

npm ERR! Failed to parse json
npm ERR! Unexpected token ' in JSON at position 212 while parsing near '...-env.dev",
npm ERR! "build": '"xcopy C:\FolderOne...'

@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants