You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
There is no such option but you can work around it. Change build in your package.jsonscripts 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!
Reacted by Iurii Kucherov, David Fox, William Le, Philip Cox, Or Duan, Rajat Saxena and ZoranZilicFTN
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 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.
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:
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...'
Activity
gaearon commentedon Sep 27, 2016
There is no such option but you can work around it. Change
buildin yourpackage.jsonscriptsto perform an additional step, likereact-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!adityashankert commentedon 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 commentedon 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 commentedon Sep 27, 2016
(Oops, didn’t mean to reopen. Fat finger.)
ChuckkNorris commentedon 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.jsonwhich would still enable other scripts to always know the build directory by reading that file.For cross-platform dev:
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
/buildfolder to the/wwwrootdirectory and removes the build directory:ZoranZilicFTN commentedon Feb 22, 2018
how would you write
for Windows.
I tried with xcopy, but when I npm run build
where
I get this error in the command line: