Hugo 用 Dartsass 替换 Libsass

Hugo 默认使用 Libsass 编译 *.scss 文件,Libsass 已经不再维护了,Sass 官方推荐使用 Dartsass。我的仓库中用到 npm 包,所以通过这一方式安装相关依赖。

netlify.toml 设置:

[build]
publish = "public"
command = """\
  mkdir -p /opt/build/repo/node_modules/.bin && \
  cp /opt/build/repo/node_modules/sass-embedded-linux-x64/dart-sass-embedded/dart-sass-embedded /opt/build/repo/node_modules/.bin && \
  dart-sass-embedded --version && \
  pnpm run all \
"""

[context.production.environment]
  HUGO_VERSION = "0.110.0"
  NODE_VERSION = "18.12.1"

以上内容并不通用,根据自己情况修改使用。

修改相关模板 themes/tianheg/layouts/partials/style.html

{{- $options := (dict "transpiler" "dartsass") -}}

参考资料




如希望撰写评论,请发邮件至 me@tianhegao.com (直接点击邮箱可自动跳转至默认邮箱App,并填写收信人和邮件主题)或者点击这里在线留言,我会挑选对读者有价值的评论附加到文章末尾。



可通过以下渠道赞赏此文