简体   繁体   English

在Node.js中包含外部CSS文件

[英]include external css files in nodejs

I want to include external css file in node.js ejs. 我想在node.js ejs中包含外部CSS文件。

I tried this but it didn't worked: 我尝试了一下,但没有成功:

app.use('/static', express.static('/view')) 

and included css like this way in ejs 并以这种方式将css包含在ejs中

<link rel="stylesheet" type="text/css" href="materialize.scss">

It always gives this error 它总是会给出这个错误

Refused to apply style from ' http://localhost:8081/static/materialize.scss ' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. 拒绝从' http:// localhost:8081 / static / materialize.scss '应用样式,因为它的MIME类型('text / html')不是受支持的样式表MIME类型,并且启用了严格的MIME检查。

You should compile first the scss into css. 您应该先将scss编译为css。 The browser doen't understand the scss code. 浏览器不了解scss代码。

npm install --save scss
sass static/materialize.scss static/css/materialize.css

Then add the link: 然后添加链接:

<link rel="stylesheet" type="text/css" href="/static/css/materialize.css">

I hope it helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM