【问题标题】:Is there a way for me to include the React production build files without using Express?有没有办法让我在不使用 Express 的情况下包含 React 生产构建文件?
【发布时间】:2020-07-22 18:32:10
【问题描述】:

我想在我的库中包含 React,但我不知道该怎么做。使用 HTTP 模块,有没有一种方法可以递归发送静态文件?我想发送 React 生产版本的 build 文件夹,但我不知道如何发送所有文件。

【问题讨论】:

  • 您能否详细说明“我想在我的库中包含 React”?您是否尝试从库中返回“自定义 React 组件”?
  • 基本上我正在尝试制作一个Web框架,但我想用它打包React。然而,其中一个要求是我必须使用该框架为 React 提供服务,而不使用 Express。

标签: javascript node.js reactjs typescript


【解决方案1】:

其实我已经找到了解决办法。你能做的是

var fs = require('fs'),
    http = require('http');

http.createServer(function (req, res) {
  fs.readFile(__dirname + req.url, function (err,data) {
    if (err) {
      res.writeHead(404);
      res.end(JSON.stringify(err));
      return;
    }
    res.writeHead(200);
    res.end(data);
  });
}).listen(8080);```
and serve static files using that way, or you can use the node-static module.

【讨论】:

    猜你喜欢
    • 2017-01-31
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 2017-05-16
    • 1970-01-01
    • 2020-09-12
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多