我需要用一些 url 替换我的 css 中的字符串,这取决于环境变量。我正在尝试使用string-replace-loader。所以我在我的 webpack 配置中有这个:
loaders: [
// ...
{test: /\.css$/, loader: `style!css!string-replace?search={{ASSETS_URL}}&replace=${ASSETS_URL}&flags=g`}
]
ASSETS_URL
即http://foo.bar/biz。
这可行,但{{ASSETS_URL}}
被 http:/foo.bar/biz 取代(http 后缺少斜杠)。
我已经记录了 string-replace-loader 的输入,它接收?search={{ASSETS_URL}}&replace=http:/localhost:8080/assets&flags=g
为this.query
.
我试图逃避斜线,但它没有帮助。
为什么会这样?有没有机会禁用这种行为?
UPD:节点版本:6.4.0,webpack 版本:1.13.2,webpack-dev-server 版本:1.16.2。