如何使用Create-React-App的节点服务器定义MIME类型? [英] How to define MIME types with Create-React-App's node server?

查看:138
本文介绍了如何使用Create-React-App的节点服务器定义MIME类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试处理此WebAssembly注释:注意:要与 instantiateStreaming compileStreaming 一起运行,您需要您的Web服务器使用 application / wasm MIME类型提供.wasm文件。https板条箱可用于提供来自本地主机的文件,并且包括application / wasm MIME类型。

I'm trying to deal with this WebAssembly note: "Note: To run with instantiateStreaming and compileStreaming, you need your webserver to serve .wasm file with application/wasm MIME type. The https crate can be used to serve files from localhost, and includes the application/wasm MIME type out of the box."

确实,我在JS控制台中收到MIME错误。 Google搜索显示无法配置此方法。 Mozilla建议在已描述的WebAssembly.instantiate上实例化Streaming。如果使用stdweb或bindgen,后者也不适合我:它想要第二个参数,我不确定该如何提供。

Indeed, I get a MIME error in the JS console. A Google search revealed no way to configure this. Mozilla recommends instantiateStreaming over the depricated WebAssembly.instantiate. The latter doesn't work for me either, if using stdweb or bindgen: It wants a second argument which I'm not sure how to provide.

推荐答案

不幸的是,您正在这里工作! WebAssembly流式编译是一项非常新的功能,仅目前在FireFox和Chrome中受支持

Unfortunately you're working on the bleeding edge here! WebAssembly streaming compilation is a very new feature that is only currently supported in FireFox and Chrome.

您说对了,这取决于文件是具有正确mime类型的服务器。为此,需要进行以下更改:

You are right that it depends on files being server with the correct mime-type. The changes required to make this happen being made:

  • node-mime - which is used by many projects (including webpack dev server) to provide mime type based on file extension, was updated to support wasm in Dec 2017 in v2.3.1
  • webpack-dev-middleware was updated in Nov 2017 to support wasm file extension in v3.1.3

但是,这些都是上游依赖项通过react-scripts创建反应应用程序。反应脚本的最新版本具有对支持wasm 的webback-dev-middleware的依赖,但是尚未发布。 npm的最新版本使用的是较旧的版本。

However, these are both up-stream dependencies of create-react-app, via react-scripts. The bleeding edge version of react-scripts has a dependency on webback-dev-middleware that supports wasm, however this hasn't been released yet. The latest version on npm uses an older version.

现在,我将转向流式编译,直到这些更改使其变为生产为止。

For now, I'd turn of streaming compilation until these changes make it into 'production'.

这篇关于如何使用Create-React-App的节点服务器定义MIME类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆