-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Create React App inside a non-empty folder #7802
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
Comments
Have you tried having another package.json local to the React app?
🤷♂ I am just taking a wild shot at this lol |
Hello, Thanks for your reply @JacobMGEvans! Haha! That is one of my first shots as well :) I also considered working with:
But:
All of them programmatically and on every save (backend serves the output). If I include the That is why It makes perfect sense to move the configuration to the root directory. I hope it makes sense to you too. Having |
Well, how I normally handle a small frontend like that is have a small server, just serving the frontend bundle... Separate from any backend I may have in the same fullstack repo. const express = require(`express`);
require(`dotenv`).config();
express()
.use(express.static(`${__dirname}/dist`))
.get(`*`, (req, res) => res.sendFile(`${__dirname}/dist/index.html`))
.listen(process.env.PORT || 1234, () => console.log(`__SERVER_RUNNING__`, process.env.PORT),
); |
Actually I think of it that would be useless unless you are building locally... or have the hot reload setup for it. I think that it's such a large configuration change that utilizing eject here is what it was made for. I know that is not the help or suggestion you were looking for, maybe someone with a deeper knowledge can give a better suggestion 😆 |
@JacobMGEvans It looks like you misunderstood me. I have a fairly big react SPA frontend and additionally, some single page exports for the non-frontend, backend-served template pages for the same look and feel (which utilizes the same layout, header, footer etc). 😉 And for the "Large configuration change", I have three or four changes:
I can do everything listed here except initializing the create-react-app app in a non-empty folder. |
Here is the export part of my const spaConfig = function (webpackEnv) {
// [...]
return {
...webpackConfig(webpackEnv),
name: 'spa-configuration',
entry: './resources/js/app.jsx',
output: {
filename: 'public/js/app.js',
chunkFilename: isEnvProduction
? 'public/js/[name].chunk.js'
: isEnvDevelopment && 'public/js/[name].chunk.js',
// [...]
},
plugins: [
// [...]
new HtmlWebpackLaravelAssetPlugin({ options: '' }),
};
};
const spConfig = function (webpackEnv) {
return {
...webpackConfig(webpackEnv),
name: 'sp-configuration',
entry: {
403: './resources/js/sp/403.jsx',
500: './resources/js/sp/500.jsx',
PostLogoutPage: './resources/js/sp/PostLogoutPage.jsx',
},
// [...]
};
};
module.exports = [spConfig, spaConfig]; |
I see. I think what you are doing is exactly why the eject is available to "own" the configurations. I would definitely be interested in what the maintainers have to say. Pretty slick that you got that to work though! |
I use
create-react-app
to create a react app inside an existing backend project which will serve the react application. And I have to run theeject
command to:.less
support with some extra configurationand so on...
To automate this process, I took a fork from
react-scripts
and I defined my folder structure. AMy final file system hierarchy should be something like:
So I edited the template folder to match these requirements and published the scripts to give a try.
npx create-react-app . --scripts-version my-react-scripts
And as you guessed, I got
However:
package.json
to be located in the project root directory.react-app
inside the existingresources
folder. And react-app will live inside this directory. I don't expect an override.Describe the solution you'd like
create-react-app
in an existing folder with some files.Maybe by setting a constant from my scripts or using an option after
npx create-react-app
call.Describe alternatives you've considered
I considered to update create-react-app to support it as well but that doesn't make sense since it would be almost impossible to follow up the updates and upgrades later.
Additional context
#334
#2776
The text was updated successfully, but these errors were encountered: