1

我需要用一些 url 替换我的 css 中的字符串,这取决于环境变量。我正在尝试使用string-replace-loader。所以我在我的 webpack 配置中有这个:

loaders: [
  // ...
  {test: /\.css$/, loader: `style!css!string-replace?search={{ASSETS_URL}}&replace=${ASSETS_URL}&flags=g`}
]

ASSETS_URLhttp://foo.bar/biz

这可行,但{{ASSETS_URL}}被 http:/foo.bar/biz 取代(http 后缺少斜杠)。

我已经记录了 string-replace-loader 的输入,它接收?search={{ASSETS_URL}}&replace=http:/localhost:8080/assets&flags=gthis.query.

我试图逃避斜线,但它没有帮助。

为什么会这样?有没有机会禁用这种行为?

UPD:节点版本:6.4.0,webpack 版本:1.13.2,webpack-dev-server 版本:1.16.2。

4

0 回答 0