Skip to content

Question: How to change output folder for build files.  #3824

Closed
@pasichnyk

Description

@pasichnyk

This is folder's structure of my project.

project_frontend /
    app/
    package.json

project_backend/
    api/
    static/
    index.html

So I launch npm run build from project_frontend and I need to put build files into project_backend. Also I don't need to put into there files like "manifest.json", "asset-manifest.json".
Thanks.

Activity

gaearon

gaearon commented on Jan 17, 2018

@gaearon
Contributor

In your package.json you have:

  "scripts": {
    "build": "react-scripts build"

You can add another script called postbuild that does something after the build and will be called by npm/Yarn automatically.

  "postbuild": "mv build ../project_backend/"

You could also run a custom script that does more.

  "postbuild": "node postbuild.js"

Hope this helps!

thecalvinchan

thecalvinchan commented on Jun 24, 2018

@thecalvinchan

i don't think this is a valid solution because it assumes that the build directory is not being used by some other service. For example, i have backend code that compiles to a build directory, then this would also affect those files as well.

True, a proper separation of concerns here would be the right move, making each their own codebase and repository, but would definitely like to see an option to set a build-dir option in react scripts

sairathb

sairathb commented on Jul 18, 2018

@sairathb

I found a way to get it to work. I was facing the same issue of moving my react build to ../public folder, since I am writing a test application and using node back end. You can run the npm run eject to get all the webpack files. then change the ./config/path.js file to update appBuild: resolveApp('../public'),

Hope that helps

pavelhamrik

pavelhamrik commented on Dec 4, 2018

@pavelhamrik

@sairathb I wouldn't eject just for this, losing the ability to update.

nsoufian

nsoufian commented on Dec 28, 2018

@nsoufian

I absolutely agree with you @pasichnyk , I have the same issues I always ejecting my react.js projects for changing the build path or adding one or two plugins to my webpack and I lose the ability to update my scripts.
I hope that react team @gaearon takes into consideration this problem and try to find
a good solution for us" React.js users" to add configurations to env or webpack without ejecting and losing the ability of updates, it's can help us a lot, for example creating new open source project that depends on create-react-app.

tanks you react team for hooks :D

locked and limited conversation to collaborators on Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @gaearon@thecalvinchan@pavelhamrik@pasichnyk@nsoufian

      Issue actions

        Question: How to change output folder for build files. · Issue #3824 · facebook/create-react-app