使用 typeface-nunito-sans 和 @poi/plugin-vue-static 时出现@font-face SyntaxError

@font-face SyntaxError when using typeface-nunito-sans and @poi/plugin-vue-static

我正在使用 Poi,@poi/plugin-vue-statictypeface-nunito-sans 使用 Vue 生成静态应用程序。问题是构建在语法错误中失败:

project/node_modules/typeface-nunito-sans/index.css:2
@font-face {
^
SyntaxError: Invalid or unexpected token

虽然整个应用程序在开发服务器中可以正常运行。这是因为生成静态站点吗?我该如何解决?

main.ts中的相关代码:

// Client-side only libraries
import 'typeface-nunito-sans';

通过添加 process.client 检查解决了这个问题:

if (process.client) {
  require('typeface-nunito-sans');
}

这可以防止 CSS 在服务器端代码中被处理