【问题标题】:How does `^` mean in Webpack DevServer Proxy pathRewrite`^` 在 Webpack DevServer Proxy pathRewrite 中是什么意思
【发布时间】:2020-08-20 04:47:53
【问题描述】:

我正在尝试理解Webpack DevServer Proxy documentation

我的目标是将任何没有 .html 的路径代理到相应的 .html 文件。示例:/foo -> /foo.html/bar -> /bar.html

我想,我需要使用pathRewrites。文档示例建议使用pathRewrite: {'^/api' : ''} 重写路径。

我还不清楚(第一个参数的)语法:插入符号 (^) 字符的含义是什么?它是正则表达式吗?语法文档在某处吗?

【问题讨论】:

    标签: javascript webpack proxy configuration webpack-dev-server


    【解决方案1】:

    找到了:

    开发服务器利用强大的 http-proxy-middleware 包。

    定义

    对象键将用作正则表达式来匹配路径。

    -> 是的,它是一个正则表达式。 ✅

    【讨论】:

      【解决方案2】:

      我试图实现与您完全相同的功能。对于这个问题的未来观众:http-proxy-middleware 目前不支持捕获组https://github.com/chimurai/http-proxy-middleware/issues/271

      因此,您必须使用自定义重写功能,将扩展名附加到您的路径中,如下所述:https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathRewrite.md#custom-rewrite-function

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-05-20
        • 2011-08-12
        • 2017-06-11
        • 2018-03-05
        • 2023-03-27
        • 2016-08-17
        • 2010-12-28
        相关资源
        最近更新 更多