简体   繁体   English

来自带有symfony 4的socket / io的webpack / encore

[英]webpack/encore from symfony 4 with socket.io

I tried to use socket.io in my symfony 4 project, still I encounter some issues. 我尝试在我的symfony 4项目中使用socket.io,但仍然遇到一些问题。 I used npm install --save socket.io 我用npm install --save socket.io

then i get this : 然后我得到这个:

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ socket.io@2.1.1
added 101 packages in 9.519s

But i was thinking "it's ok, it just notice me and it look optionnal". 但是我当时在想“没关系,它只是注意到我,而且看起来像是可选的”。

Still when i used webpack/encore i get : 仍然当我使用webpack / encore我得到:

PS C:\wamp64\www\PROJETS\my-projet> ./node_modules/.bin/encore dev
Running webpack ...

 ERROR  Failed to compile with 2 errors                                                                         15:41:22

These dependencies were not found:

* fs in ./node_modules/socket.io/lib/index.js
* uws in ./node_modules/engine.io/lib/server.js

To install them, you can run: npm install --save fs uws

But install what they want ( fs uws ) don't make it work better when i use webpack/encore ... What should i do ? 但是安装他们想要的东西( fs uws )并不能使它在使用webpack / encore时更好地工作...我该怎么办?

socket.io is a server side node.js package, you are not supposed to run using webpack. socket.io是服务器端的node.js程序包,不应使用webpack运行。 Maybe you are looking for socket.io-client ? 也许您在寻找socket.io-client Otherwise, you should use a separate node.js environment. 否则,您应该使用单独的node.js环境。

It works, client side can be compiled now. 它可以工作,客户端现在可以编译。 I used import io from 'socket.io-client'; 从'socket.io-client'使用import io; .

Server side i did it by this way : let io = require('socket.io')(server); 服务器端我是通过这种方式完成的: let io = require('socket.io')(server); .

But i'm thinking (server side) that for deployement webpack/encore will not compile libraries, then should i add them in sub folder of my Server App ? 但是我(服务器端)认为对于部署webpack / encore不会编译库,那么我应该将它们添加到Server App的子文件夹中吗?

Something like this : 像这样的东西:

Symfony 4 project | assets | bin | config | server_app | | server_app.js | | lib | | | here lib for socket.io | public | src | template ...

(my question may seem stupide) if I wont add all node_modules folder on my server, should I copy paste socket.io's folder from node_modules to the new folder " lib " indicated above ? (我的问题似乎很愚蠢)如果我不将服务器上的所有node_modules文件夹添加到服务器,是否应该将socket.io的文件夹粘贴从node_modules复制到上述新文件夹“ lib ”? (all or part) (全部或部分)

Else is it a wrong way to deploy it ? 否则部署它是错误的方法吗? (sorry, i'm not familiar with it, I normaly only upload the compiled file from Encore ... then when I need to deploy a server side app ...) (对不起,我不熟悉,我通常只从Encore上传已编译的文件...然后当我需要部署服务器端应用程序时...)

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

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