当我尝试在谷歌浏览器上使用我的 LESS 文件时,它在控制台上出现了这个错误:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
less.js:446 XMLHttpRequest cannot load file:///path/core.less. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
我已经下载了 less.js 并将其放在脚本标签中,如下所示
head class="Setup">
<!-- LESS -->
<link rel="stylesheet/less" type="text/css" href="path/core.less"/>
<script src="path/less.js" type="text/javascript"></script>
但是,如果我为我的文本编辑器使用一个包,即 https://atom.io/packages/browser-plus它工作正常。控制台日志:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
less.js:837 rendered file:///path/core.less successfully.
less.js:837 css for file:///path/core.less generated in 67ms
less.js:837 less has finished. css generated in 67ms
检查 Google Chrome 版本后,文本编辑器使用版本 47,而我的普通 chrome 使用版本 50。我不知道发生了什么。有解决办法吗?
编辑:发现less.js not working in chrome 因为我不知道如何设置 Apache,所以我尝试搜索如何创建命令行开关,结果显示了 Windows 结果,而我使用的是 Mac。
最佳答案
正如您已经正确识别的那样,LESS.js 无法在 Chrome 中使用 file://
URL 方案:
P.S.S. Less.js browser script currently won’t work if you’re using Chrome and the path to your page starts with “file:///” due to a known Chrome issue.
由于您运行的是 Mac OSX,我建议您安装 MAMP,因为它可以让您省去设置本地服务器的麻烦:
关于css - 尝试对文件 ://使用 LESS 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36925638/