Search code examples
reactjscreate-react-appyarnpkg

Change src/ folder to something else when yarn start


I'm in the process of writing a web app but I constantly see something that really wakes my OCD up. The "src" folder created by create-react-app just doesn't fit well with my idea of folder structure, I'd rather put my views inside a folder called "views". I tried to search for a solution but all I found was "create a symlink". Is there any way to make create-react-app to nominate "src" with some other names?


Solution

  • You can yarn run eject your CRA boilerplate to Tweak with webpack.config.js. yarn run eject reveals the entire preloaders and plugins used to compile your project.

    sample script from webpack's wiki

    {
        context: __dirname + "/views",
        entry: "./entry",
        output: {
            path: __dirname + "/dist",
            filename: "bundle.js"
        }
    }
    

    Important

    yarn run eject is a one-way road and you cannot revert back. so be careful.