-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Customize build folder #1354
Comments
EDIT: this way is not supported and can be broken anytime there's an update to react-scriptsI wrote an article about that in here: https://medium.com/@viankakrisna/extending-create-react-app-webpack-config-c70828593c96#.o8n88apglbasically, you can just create a webpack.config.js with this code inside it on your app root
install webpack, and
voila! you customized the build path. |
Note that the above way of using Create React App is entirely unsupported and can break in any version. |
I imagine that we will allow this once we add some basic configuration. However this is not going to happen in the next few months. Some time during 2017, maybe. |
+1 to this. The above method is kinda hacky and I found it while debugging a production bug. |
Yea, it's definitely fine for one-off changes, just not something I'd recommend checking in. |
btw. This feature is useful along with entry point customizing.
But anyway we should not expect such customizations in near future :)
|
Another direction we could explore here is making it easy for independent apps to share the same components and modules. This way you don't need multiple entries—you just have multiple apps. |
Seeing as Github Pages allows for using a /docs folder on the master branch, it would be handy to allow changing /build to /docs |
You can do this with something like: "build": "react-scripts build && mv build docs" in I think this is a good enough workaround for now, so I’ll close this request. |
This workaround doesn't help for debug mode, when I need web pack to watch files and put them into correct folder... |
The feature you are requesting (a watching mode producing a development bundle on disk) is different from the feature requested in this thread (different output folder). They are somewhat related, but currently there is no support for writing development bundles to disk at all. You can voice support for it by searching for the respective issue and clicking a thumbs up or leaving a comment there. But this is not very relevant for this request, as we don’t currently support writing development bundle to disk in the first place. I don’t think it is strange this feature is missing. Largely, it is intentional. It ensures most people have similar setups, and people can build tools (e.g. for deployment) assuming the same directory structure. I understand there are exceptions where this is necessary, but with the current feature set just adding a |
The suggested workaround is insufficient for me, and I'm curious how you'd solve my current setup. The folder structure looks like this: /my-cra-app/build/index.html (et al) I need by index.php to do cookie/login checking and to serve initial data. I could just copy the build folder over to the htdocs folder as static or something, then read the HTML into the PHP and stream it out, but then all the URLs to JS and CSS files would be wrong, since they're not pointing to the static folder. Additionally, how does one inject initial data into the CRA HTML file? I could put an extra <script> tag to load the data, but that's an additional blocking script load that should be avoidable. How have people properly made CRA apps work with dynamically generated landing pages? Is the extra <script> the only solution to doing proper login/cookie checking or is there some templating solution available for the index.html file? |
You can add
to
If you want to serve from
Generally we recommend this: CRA output is just a static file, so any strategy that would work with a static file would work for us too. We don't support any particular templating syntax but you can come up with your own interpolation that's completely replaced on server side. |
Quick workaound: |
For those wanting a simple deploy to their Github repo
<!doctype html>
<html lang="en">
<head>
<!-- Meta Data -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Rerouting -->
<script type="text/javascript">!function(i){if(i.search){var a={};i.search.slice(1).split("&").forEach(function(i){var l=i.split("=");a[l[0]]=l.slice(1).join("=").replace(/~and~/g,"&")}),void 0!==a.p&&window.history.replaceState(null,null,i.pathname.slice(0,-1)+(a.p||"")+(a.q?"?"+a.q:"")+i.hash)}}(window.location);</script>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
</body>
</html>
After all this, you can simply run |
…uecomment-316890832
Quick compatibility build script (also works on Windows): "build": "react-scripts build && mv build docs || move build docs", |
@franciscop-invast thanks, much simpler solution! |
@TimoSolo on Windows it gets built from scratch on our CI platform, while on Linux for my personal projects I ended up doing exactly the same thing! |
I'm currently wanting to build different apps based off config also and would like to specify an output directory for each. Going to use the unsupported webpack hack above for now. |
Unfortunately github user pages doesn't support /docs folder(only support index.html on master branch) so the suggested solutions doesn't work. I'm currently using webpack to configure the build manually. Is there any way create react app can support Github user/org pages? |
yarn global add -E mvy package.json {
"scripts": {
"build": "react-scripts build",
"postbuild": "mvy build dist"
}
} Regards, |
for some reason in Windows, adding |
It's not about 2018, it's all about windows and yes, people still having problems with it... I was facing with similar windows issues (removing files from filesystem) not only with npm, same think in gradle / maven - while on unix systems like mac / linux everything is working as expected, windows files maybe in use, or at least windows think so. Regards |
Let's say your build directory is dist,
|
for Windows users: edit your package.json
|
This has the potential for great disaster. I'm not sure what you mean with |
No, I meant the directory where you want your build should be at. and yeah, you're right, it has "the potential for great disaster" if you really don't know what you are doing. I renamed it to "deployment directory" |
Any plan here to have this feature still? @gaearon |
To anyone looking for a solution to this, here is mine: Add module-alias:
Create these two files in your root directory:
require('module-alias/register');
require('react-scripts/scripts/build');
const paths = require('react-scripts/config/paths');
const path = require('path');
// Change 'dist' here to whatever build directory you need.
paths.appBuild = path.resolve(paths.appPath, 'dist');
module.exports = paths; Add this section to your "_moduleAliases": {
"../config/paths" : "./react-scripts-wrapper-paths",
"./paths" : "./react-scripts-wrapper-paths"
} In your |
The move after build solution doesn’t work for me. My build system generates the build folder somewhere else and symlinks it into the project directory. It fills it with some important metadata files, and when CRA builds, it wipes the build folder clean, removing these metadata files. I need to be able to specify a sub folder of the build directory. |
@hperrin Do you know if your solution is any less likely to break than the first solution suggested in this thread on updates to react-scripts? |
@bschlenk That's exactly what my build process does, which is why I can't use @gaearon's solution. I have no idea how likely @viankakrisna's or my solution is to break in the future. Both depend on internal configuration structure to react-scripts, which is not documented. |
On a project I'm currently working on, we're using a file called BUILD that specifies build instructions for our microservices.
and due to Mac OS Sierra, case insensitivity is an issue, so being able to do something like
react-scripts build --path dist
would be ideal in the package.jsonis this possible currently?
The text was updated successfully, but these errors were encountered: