我用create-react-app包创建了一个ReactJS项目,工作得很好,但我找不到webpack文件和配置。

react-create-app如何与webpack一起工作?webpack配置文件位于create-react-app的默认安装中的哪里?我无法在项目文件夹中找到配置文件。

我没有创建覆盖配置文件。我可以用其他文章管理配置设置,但我想找到传统的配置文件。


当前回答

我正在使用craco的create-react-app,当我用craco.config.js更新到webpack 5时,我能够覆盖我的webpack配置:

module.exports = {
    style: {
        postcssOptions: {
            plugins: [
            require('tailwindcss'),
            require('autoprefixer'),
            ],
        },
    },
    webpack: {
        configure: (webpackConfig, { env, paths }) => {
            // eslint-disable-next-line no-param-reassign
            webpackConfig.resolve.fallback = {
                fs: false,
            };
            return webpackConfig;
        },
    },
}

其他回答

Webpack配置由react-scripts处理。 你可以在node_modules react-scripts/config中找到所有的webpack配置。

如果你想自定义webpack配置,你可以遵循这个custom -webpack-config

尝试弹出配置文件,通过运行:

npm run eject

然后你会发现在你的项目中创建了一个配置文件夹。你会发现你的webpack配置文件init。

create-react-app使用的Webpack配置在这里: https://github.com/facebook/create-react-app/tree/master/packages/react-scripts/config

我正在使用craco的create-react-app,当我用craco.config.js更新到webpack 5时,我能够覆盖我的webpack配置:

module.exports = {
    style: {
        postcssOptions: {
            plugins: [
            require('tailwindcss'),
            require('autoprefixer'),
            ],
        },
    },
    webpack: {
        configure: (webpackConfig, { env, paths }) => {
            // eslint-disable-next-line no-param-reassign
            webpackConfig.resolve.fallback = {
                fs: false,
            };
            return webpackConfig;
        },
    },
}

您可以在/config文件夹中找到它。

当你弹出时,你会收到这样的消息:

 Adding /config/webpack.config.dev.js to the project
 Adding /config/webpack.config.prod.js to the project