question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

custom absolute path for npm build

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
gaearoncommented, Sep 27, 2016

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!

2reactions
ZoranZilicFTNcommented, Feb 22, 2018

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…’

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use Absolute Path for npm run build - Stack Overflow
So for my ReactJs project, I am using absolute path for import, like this import {button} from /buttons. instead of relative path like...
Read more >
require absolute path - npm search
Resolves a given package if it is installed locally, then tries to resolve it from global registry, using battle-tested [global-modules][] package.
Read more >
Absolute imports with Create React App | by David Gilbertson
WebStorm assumes absolute paths are in node_modules (as per the Node.js rules), so we must tell it that we're being fancy and using...
Read more >
Use Absolute Paths with React - Better Programming
It can be done using a Resolver — a library that helps in locating a module by its absolute path. In the Webpack...
Read more >
Advanced Features: Absolute Imports and Module Path Aliases
These options allow you to configure module aliases, for example a common pattern is aliasing certain directories to use absolute paths.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found