通过 config-overrides.js 添加 webpack 插件

发布于 2025-01-15 14:07:28 字数 195 浏览 1 评论 0原文

我正在使用带有自定义配置的 React 应用程序,无需弹出,为此我正在使用 React-app-rewire。为了向 webpack 提供插件,我使用了react-app-rewire-provide-plugin。将我的反应脚本更新到最新版本后,反应应用程序重新布线提供插件不支持。因此我需要找到一种方法将插件添加到我的 webpack 配置中。有什么解决办法吗? 提前致谢

I'm using react app with customized configuration without ejecting and for that I'm using react-app-rewire. To provide plugins to webpack, I used react-app-rewire-provide-plugin. After updating my react-scripts to the latest version the react-app-rewire-provide-plugin is not supporting. Therefore I need to find a method to add plugins to my webpack configuration. Any solutions?
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑咖 2025-01-22 14:07:28
const {
  override,
  addBabelPlugins,
  addExternalBabelPlugins,
  addWebpackPlugin,
} = require('customize-cra');

const {DefinePlugin} = require('webpack');

module.exports = override(
  ...addBabelPlugins('babel-plugin-react-native-web'),
  ...addExternalBabelPlugins(
    'react-native-web',
    ['@babel/plugin-proposal-decorators', {legacy: true}],
  ),
  addWebpackPlugin(
    new DefinePlugin({
      __DEV__: process.env.NODE_ENV !== 'production',
    }),
  ),
);

真实示例: https://github.com/criszz77/luna/blob/ccaac73f82574fb409b69843e260dd58a3f68f8c/template/config-overrides.js

我一直在使用react-app-rewired和customize-cra将插件传递给webpack 无需弹出。

你在这里看到的是一个用react-app-rewired替换craco的PR(显然它现在可以在react-scripts@5中使用)

const {
  override,
  addBabelPlugins,
  addExternalBabelPlugins,
  addWebpackPlugin,
} = require('customize-cra');

const {DefinePlugin} = require('webpack');

module.exports = override(
  ...addBabelPlugins('babel-plugin-react-native-web'),
  ...addExternalBabelPlugins(
    'react-native-web',
    ['@babel/plugin-proposal-decorators', {legacy: true}],
  ),
  addWebpackPlugin(
    new DefinePlugin({
      __DEV__: process.env.NODE_ENV !== 'production',
    }),
  ),
);

Real example: https://github.com/criszz77/luna/blob/ccaac73f82574fb409b69843e260dd58a3f68f8c/template/config-overrides.js

I’ve been using react-app-rewired along with customize-cra to pass plugins to the webpack without ejecting.

What you’re seeing here is a PR to replace craco with react-app-rewired (apparently it works wirh react-scripts@5 now)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文