【问题标题】:grunt-usemin don't replace image pathsgrunt-usemin 不替换图像路径
【发布时间】:2023-03-17 05:33:01
【问题描述】:

我不知道是否有人问过这个答案,但我没有找到相关的帖子。 我用 grunt 构建我的静态页面,并在“/dist/index.html”下生成我的“index.html”后,我在该文件上使用 usemin(和 useminPrepare)运行以合并和缩小我的 css 和 js 文件,这些文件可以正常工作。

但我的 index.html 中相关的图像不会被替换(并从源代码复制)...

例如我想要下面的代码

<img src="/src/assets/images/my-image.png" width="50" height="50" alt="My alt title" />

在 /dist/index.html 下被替换为

<img src="/images/my-image.png" width="50" height="50" alt="My alt title" />

并且图像也从 /src/assets/images/my-image.png 复制到 /dist/images/my-image.png。

我怎样才能做到这一点?

提前致谢。

【问题讨论】:

  • 没有人能解决这个问题吗?或者有其他方法来实现这一点?

标签: gruntjs grunt-usemin


【解决方案1】:

使用节点包“grunt-string-replace”解决了问题(参见https://www.npmjs.org/package/grunt-string-replace)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多