繁体   English   中英

Typescript setupProxy.js 带有自定义 webPack 配置

[英]Typescript setupProxy.js whit custom webPack config

我必须在 typescript React 应用程序的 setupProxy.js 中将 header Access-Control-Allow-Origin设置为* 但我不能。 我不确定是否支持 typescript 中的 setupProxy.js (ts)。

但我需要它用于微前端应用程序。

这是我的自定义 webpack 配置(使用 react-app-rewired)

module.exports = {
    webpack: (config, env) => {
      config.optimization.runtimeChunk = false;
      config.optimization.splitChunks = {
        cacheGroups: {
          default: false,
        },
      };
  
      config.output.filename = "static/js/[name].js";
  
      config.plugins[5].options.filename = "static/css/[name].css";
      config.plugins[5].options.moduleFilename = () => "static/css/main.css";
      return config;
    },
  };

这是我的 src/setupProxy.js

module.exports = (app) => {
    app.use((req, res, next) => {
      res.header("Access-Control-Allow-Origin", "*");
      next();
    });
  };

还有我的 npm 脚本

"scripts": {
    "start": "PORT=3031 react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

如果有另一种方法来实现我想要的,那就太棒了。

我的错,我使用 CRA 创建了 react 应用程序,然后添加了 TS,正确的方法是使用npx create-react-app my-app --template typescript

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM