問題描述
我正在開發一個使用 gulp
進行編譯和瀏覽器同步的網站,以使瀏覽器與我的更改保持同步.
I'm working on a website that uses gulp
to compile and browser sync to keep the browser synchronised with my changes.
gulp 任務可以正確編譯所有內容,但是在網站上,我看不到任何樣式,并且控制臺顯示此錯誤消息:
The gulp task compiles everything properly, but on the website, I'm unable to see any style, and the console shows this error message:
拒絕應用樣式來自'http://localhost:3000/assets/styles/custom-style.css' 因為它MIME 類型 ('text/html') 不是受支持的樣式表 MIME 類型,并且已啟用嚴格的 MIME 檢查.
Refused to apply style from 'http://localhost:3000/assets/styles/custom-style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
現在,我真的不明白為什么會發生這種情況.
Now, I don't really understand why this happens.
HTML 包含這樣的文件(我很確定這是正確的):
The HTML includes the file like this (which I am pretty sure is correct):
<link rel="stylesheet" type="text/css" href="assets/styles/custom-style.css"/>
樣式表是 Bootstrap 和目前字體很棒的樣式(還沒有自定義).
And the stylesheet is a merge between Bootstrap & font-awesome styles for now (nothing custom yet).
路徑也是正確的,因為這是文件夾結構:
The path is correct as well, as this is the folder structure:
index.html
assets
|-styles
|-custom-style.css
但我不斷收到錯誤消息.
But I keep getting the error.
可能是什么?這可能是 gulp/browsersync 的東西(可能是設置?)?
What could it be? Is this something (maybe a setting?) for gulp/browsersync maybe?
推薦答案
我已將我的 href
更改為 src
.所以從這里:
I have changed my href
to src
. So from this:
<link rel="stylesheet" href="dist/photoswipe.css">
到這里:
<link rel="stylesheet" src="dist/photoswipe.css">
成功了.我不知道為什么,但它確實起到了作用.
It worked. I don't know why, but it did the job.
這篇關于由于 MIME 類型而未加載樣式表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!