简体   繁体   English

覆盖 CRA webpack 配置而不弹出(从媒体文件中删除随机数)

[英]Override CRA webpack config without ejecting (remove random numbers from media files)

I need to remove generated random numbers from all pdf files names in my project.我需要从项目中的所有pdf文件名中删除生成的随机数。 (for example license.pdf instead of license.3402bc5d.pdf) (例如 license.pdf 而不是 license.3402bc5d.pdf)

I tried to use react-app-rewired .我尝试使用react-app-rewired

file config-overrides.js :文件config-overrides.js

module.exports = function override(config, env) {
  config.module = {
    ...config.module, // copy all settings
    rules: [
      ...config.module.rules,
      {
        oneOf: [
          {
            test:/\.pdf$/,
            loader: 'file-loader',
            options: { name: "static/media/[name].pdf"}
          }
        ]
      },
    ]
  };
  return config;
};

But it didn't work但它没有用

Here is the solution:这是解决方案:

module.exports = function override(config, env) {
  config.module.rules[1].oneOf = config.module.rules[1].oneOf.map((one) => {
    if (one.options && one.options.name && one.exclude) {
      one.exclude = [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/, /\.pdf$/];
    }
    return one;
  }).concat([
    {
      test:/\.pdf$/,
      loader: 'file-loader',
      options: { name: "/docs/[name].[ext]"}
    }
  ]);

  return config;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在不弹出的情况下覆盖CRA 3.x上的webpack配置 - Override webpack config on CRA 3.x without ejecting CRA 5 升级到 Webpack 5. 在不弹出 CRA 的情况下使用 Webpack 模块联合有什么帮助? - CRA 5 upgraded to Webpack 5. How does it help using Webpack Module Federation with CRA without ejecting? 是否有更好的包含或将CDN中的CSS导入CRA应用程序而不会弹出 - Is there a better include or import CSS from CDN into a CRA app without ejecting Create-react-app + TypeScript + CSS 模块:自动生成类型定义而不从 CRA 中弹出 - Create-react-app + TypeScript + CSS Modules: Auto-generating type definitions without ejecting from CRA CRA webpack - 输出单独的文件 - CRA webpack - output separate files 从 CRA 弹出以共享组件,共享目录未被检查 - Ejecting from CRA to share components the shared directory are not linted create-react-app + Webpack 5 不弹出 - create-react-app + Webpack 5 without ejecting 意外的令牌导入而没有弹出/更新配置 - unexpected token import without ejecting/updating config 通过 webpack config-override 将所有 css 文件合并为一个 - Combine all css files into one via webpack config-override 有没有办法在不弹出的情况下为 create-react-app 更改 webpack 的 eslint - Is there a way to change the eslint of the webpack for the create-react-app without ejecting
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM