javascript - 使用 Pug 视图引擎时 Express less-middleware 不编译
问题描述
我对使用 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'));
...
家.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 compile but I've tried everything I can and I'm out of idea.
抱歉,如果这真的很愚蠢/简单,但我觉得我现在正试图解决这个问题。任何帮助将非常感激
谢谢
解决方案
推荐阅读
- r - 我无法理解 R 中的闭包是如何工作的
- reactjs - React useEffect 用于加载数据
- ios - 如何为 UIFontMetrics 指定最小 UIContentSizeCategory?
- ssl - 403 - 禁止访问被拒绝。IIS
- reactjs - 如何从对象生成动态选择框
- java - z3 Solver:使用“parseSMTLIB2String”与rise4fun 在线工具获得不同的结果
- mysql - python3计算自上次mysql数据输入以来的分钟数
- c# - 在带有 C# 的 Visual Studio 中使用 Windows 窗体,有没有办法让 Graphics.DrawEllipse 函数完全按照指定绘制椭圆?
- vuejs2 - Vue多选表单相互独立
- javascript - 无法使用 jQuery 选择元素的兄弟姐妹