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.

How can I override the build directory?

See original GitHub issue

I’m trying to override the build folder by changing webpackConfig.output.path, here is my craco.config.js file:

const path = require('path');

const overrideWebpackConfig = ({ webpackConfig }) => {
  webpackConfig.output.path = path.resolve('my', 'custom', 'folder');
  return webpackConfig;
};

module.exports = {
  plugins: [
    {
      plugin: { overrideWebpackConfig }
    }
  ]
};

When running craco build, it works until the very end, when react-scripts tries to print out the gzipped size of all the files. I get the error:

ENOENT: no such file or directory, open '/path/to/project/MyProject/build/static/css/main.16e7b84a.chunk.css'

This is still looking at the build folder, not my/custom/folder. Digging into it, react-scripts has this file node_modules/react-scripts/config/paths.js which is being used. Is there a way to modify this file using craco?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

17reactions
spartakbcommented, Jan 18, 2021

Replying to an old thread here, but the following approach worked for me so maybe it will help someone searching for an answer in the future.

const path = require('path');

module.exports = {
   webpack: {
        configure: (webpackConfig, { env, paths }) => { 
            paths.appBuild = webpackConfig.output.path = path.resolve('custom-build-dir');
        }
    }
}

PS: Any unexpected issues I should be aware of with this approach?

11reactions
shaoyanmincommented, Feb 2, 2021
const path = require('path');

module.exports = {
   webpack: {
        configure: (webpackConfig, { env, paths }) => { 
            paths.appBuild = webpackConfig.output.path = path.resolve('custom-build-dir');
        }
    }
}

@spartakb you should return webpackConfig in the end of the function. Then it works for me, thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I override the build directory? · Issue #104 - GitHub
I'm trying to override the build folder by changing webpackConfig.output.path, here is my craco.config.js file: const path = require('path') ...
Read more >
Override build steps - doc - snapcraft.io
This can be done by utilising the override-build override. Its working directory is the part's base build directory in parts/<part name>/build/ .
Read more >
Is there a way to override build and dist directories that ...
1 Answer 1 · 1) First I edited nbproject/project.properties file and added a variable for toplevel build dir. · 2) Then I made...
Read more >
how to override the build folder per project via cmake
You can change the build directory in CMake profile (File | Settings | Build, Execution, Deployment | CMake) - https://www.jetbrains.com/help/ ...
Read more >
Change the build output directory - Visual Studio (Windows)
Change the build output directory · For C#, select the Build tab. · For Visual Basic, select the Compile tab. · For C++...
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