使用 Pug 视图引擎时表示较少中间件未编译

问题描述

我刚开始使用 Express 和 Pug,但我知道这应该很简单。

我试图让我的 Pug 视图使用由 less-middleware 模块编译的 css 文件,但我似乎无法让 less-middleware 将我的 less 文件编译成 css。

index.js

const express = require('express');
const lessMiddleware = require('less-middleware');
const app = express();
...
app.set('view engine','pug');
app.set('views','./views');
app.use(lessMiddleware(__dirname + '/public'));
app.use(express.static(__dirname + '/public'));
...

home.pug

html
    head
        title title
        link(rel="stylesheet" type="text/css" href="../public/style.css")

文件结构

/public
    style.less
/src
    index.js
/views
    ...
    home.pug

转到 http://localhost:3000/home 会出现此错误消息:

Refused to apply style from 'http://localhost:3000/public/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type,and strict MIME checking is enabled.

现在我知道这意味着 style.css 文件不存在(我认为),这源于 less-middleware 没有将 less 编译成 css,对吗?

我知道这实际上是其他问题的副本,例如:Express less-middleware not compiling,但我已经尽我所能,但我没有想法。

如果这真的很愚蠢/简单,我深表歉意,但我觉得我现在正用头撞砖墙试图解决这个问题。任何帮助将不胜感激

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)