除非CSS文件扩展名以.css结尾,否则无法从文件URL加载CSS. [英] CSS cannot be loaded from `file:` URLs unless they end in a `.css` file extension

查看:349
本文介绍了除非CSS文件扩展名以.css结尾,否则无法从文件URL加载CSS.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次尝试使用sass而不是CSS,但是当我尝试加载样式表时,浏览器告诉我它只能加载.css作为样式表.这是html

i'm trying for the first time to use sass and not css but when i try to load the stylesheet the browser tell me that it can only load .css as stylesheet. Here is the html

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="./index_style.scss">
  </head>
  <body>

  </body>
</html>

错误

[Deprecation] CSS cannot be loaded from `file:` URLs unless they end in a `.css` file extension.

我正在使用chrome

i'm using chrome

推荐答案

SASS是预处理器,浏览器不了解.scss,而仅了解.css.SASS将.scss文件转换为.css.

SASS is a preprocessor, the browser doesn't understand .scss, but only .css. SASS converts .scss files to .css.

可能有一些项目允许从HTTP服务器即时"动态加载.scss文件,但该消息表明您是直接从本地文件系统加载页面.

There may be some projects that allow loading dynamically a .scss file "on the fly" from a HTTP server, but the message indicates that you are loading the page directly from your local file system.

在这种情况下,您需要调用预处理器并将 link 上的 href 指向生成的文件.可以使用命令行命令直接完成操作,并在此处找到说明( https://sass-lang.com/guide ),或者如果您使用的是任务运行程序(例如grunt,gulp等),那么其中就有Sass的任务.

In that case you need to invoke the preprocessor and point the href on the link to the generated file. It can be done directly with a command line command, with the instructions you can find here (https://sass-lang.com/guide) or if you are using a task runner like grunt, gulp, etc. there are task for Sass in those.

这篇关于除非CSS文件扩展名以.css结尾,否则无法从文件URL加载CSS.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆