Skip to content

custom absolute path for npm build #778

Closed

Description

@adityashankert

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

Activity

  1. gaearon commented on Sep 27, 2016

    @gaearon
    Contributor

    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!

  2. adityashankert commented on Sep 27, 2016

    @adityashankert
    Author

    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?

  3. gaearon commented on Sep 27, 2016

    @gaearon
    Contributor

    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.

  4. gaearon commented on Sep 27, 2016

    @gaearon
    Contributor

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

  5. ChuckkNorris commented on Aug 26, 2017

    @ChuckkNorris

    @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",
      }
    
  6. ZoranZilicFTN commented on Feb 22, 2018

    @ZoranZilicFTN

    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...'

  7. locked and limited conversation to collaborators on Jan 20, 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

      Development

      No branches or pull requests

      Issue actions