如何让webpack和iis express一起工作? [英] How to get webpack and iis express to work together?

查看:161
本文介绍了如何让webpack和iis express一起工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Angular 2和Webpack 2 starter ,它们由webpack-dev在节点上运行-server,我用visual-api从visual studio运行它。



问题是当angular2-webpack-starter在端口3000上运行webpack-dev-server时。和IIS Express在不同的端口5000上运行。



这对我来说非常重要,因为我想使用HMR并在每次更改文件时重新加载。



那么,如何将它们组合在一起?在同一个端口上运行?或任何其他解决方案?

解决方案

我找到了! - 结合现有服务器
摘要和示例:



您可能希望在开发中运行后端服务器或模拟它。您不应该使用webpack-dev-server作为后端。它的唯一目的是提供静态(webpacked)资产。



你可以并排运行两个服务器:webpack-dev-server和你的后端服务器。 / p>

在这种情况下,您需要教webpack生成的资产,即使在后端服务器发送的HTML页面上运行时也向webpack-dev-server发出请求。另一方面,您需要教您的后端服务器生成HTML页面,其中包含指向webpack-dev-server上资产的脚本标记。除此之外,您需要webpack-dev-server和webpack-dev-server运行时之间的连接以在重新编译时触发重新加载。



教webpack发出请求(对于块加载或HMR)到webpack-dev-server,你需要在output.publicPath选项中提供一个完整的URL。



在webpack-之间建立连接 - dev-server及其运行时最佳,使用带有--inline的内联模式。 webpack-dev-server CLI自动包含一个建立WebSocket连接的入口点。 (如果将webpack-dev-server的--content-base指向后端服务器,也可以使用iframe模式。如果需要与后端服务器建立websocket连接,则必须使用iframe模式。



使用内联模式时,只需在Web浏览器中打开后端服务器URL。(如果使用iframe模式,请打开/ webpack-dev-server /前缀的URL webpack-dev-server。)



https://webpack.github.io/docs/webpack-dev-server.html#combining-with-an-existing-server


I have Angular 2 and Webpack 2 starter which run on node by webpack-dev-server, and I what to run it from visual studio with web-api.

The problem is when angular2-webpack-starter run webpack-dev-server on port 3000. and IIS Express run on different port 5000.

This is very important to me because I want to use HMR and reload every time the files are changed.

So, How can be combine them together? run on the same port? or any other solution?

解决方案

I found it ! - Combining with an existing server Summary and example:

You may want to run a backend server or a mock of it in development. You should not use the webpack-dev-server as a backend. Its only purpose is to serve static (webpacked) assets.

You can run two servers side-by-side: The webpack-dev-server and your backend server.

In this case you need to teach the webpack-generated assets to make requests to the webpack-dev-server even when running on a HTML-page sent by the backend server. On the other side you need to teach your backend server to generate HTML pages that include script tags that point to assets on the webpack-dev-server. In addition to that you need a connection between the webpack-dev-server and the webpack-dev-server runtime to trigger reloads on recompilation.

To teach webpack to make requests (for chunk loading or HMR) to the webpack-dev-server you need to provide a full URL in the output.publicPath option.

To make a connection between webpack-dev-server and its runtime best, use the inline mode with --inline. The webpack-dev-server CLI automatically includes an entry point which establishes a WebSocket connection. (You can also use the iframe mode if you point --content-base of the webpack-dev-server to your backend server. If you need a websocket connection to your backend server, you’ll have to use iframe mode.

When you use the inline mode just open the backend server URL in your web browsers. (If you use the iframe mode open the /webpack-dev-server/ prefixed URL of the webpack-dev-server.)

https://webpack.github.io/docs/webpack-dev-server.html#combining-with-an-existing-server

这篇关于如何让webpack和iis express一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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