简体   繁体   English

在生产模式 Javascript 下不加载较少的文件

[英]Less files are not loading on production mode Javascript

I am new in CSS Preprocessors and trying to get my head around less.js我是 CSS 预处理器的新手,并试图了解 less.js

Following is my code:以下是我的代码:

Main.jsp: Main.jsp:

<link rel="stylesheet/less" type="text/css" href="${pageContext.request.contextPath}/js/theme/theme-style.less"/>
<link rel="stylesheet/less" type="text/css" href="${pageContext.request.contextPath}/js/theme/theme-variable.less"/>
<script src="${pageContext.request.contextPath}/less/less.js"></script>

theme-variable.less主题变量.less

@tb-header-bg :#012f46;

theme-style.less主题风格.less

@import "./theme-variable.less";

.th-background-header {
  background: @tb-header-bg;
}

Well this is working fine on my localhost but when I deploy application on production mode its not working, theme-variable.less & theme-style.less files not loading/compiling and showing blank however less.js plugin is loading and showing its code.好吧,这在我的本地主机上运行良好,但是当我在生产模式下部署应用程序时它不起作用, theme-variable.less & theme-style.less文件没有加载/编译并显示空白但是 less.js 插件正在加载并显示其代码.

Not able to understand where I am going wrong.无法理解我哪里出错了。

NOTE: While doing some research on Google & mentioned in the less docs I found that its not best practice to compile "less.js" directly on the browser"注意:在对 Google 进行一些研究并在 less 文档中提到时,我发现直接在浏览器上编译“less.js”并不是最佳实践”

Using Less.js in the browser is the easiest way to get started and convenient for developing with Less, but in production, when performance and reliability is important, we recommend pre-compiling using Node.js or one of the many third party tools available.在浏览器中使用 Less.js 是开始使用 Less.js 开发的最简单方法,但在生产中,当性能和可靠性很重要时,我们建议使用 Node.js 或许多可用的第三方工具之一进行预编译。

But currently I am not focusing on the performance issue and just want to test on prod mode.但目前我并不关注性能问题,只想在 prod 模式下进行测试。

Thanks谢谢

Likely your production web server doesn't know how to serve.less files (your web server needs a MIME type entry for.less).您的生产 web 服务器可能不知道如何提供.less 文件(您的 web 服务器需要一个 MIME 类型条目 for.less)。 That said, you're already using angular and webpack?也就是说,您已经在使用 angular 和 webpack? If yes, Google for a LESS Webpack loader.如果是,谷歌搜索 LESS Webpack 加载程序。 It will convert your LESS to CSS, and also bundle this CSS with your JS.它会将您的 LESS 转换为 CSS,并将此 CSS 与您的 JS 捆绑在一起。

I solved it myself by adding less.js CDN and moving files from current location to another location.我通过添加 less.js CDN 并将文件从当前位置移动到另一个位置自己解决了这个问题。

Like this:像这样:

<link rel="stylesheet/less" type="text/css" href="${pageContext.request.contextPath}/less/theme-style.less"/>
    <link rel="stylesheet/less" type="text/css" href="${pageContext.request.contextPath}/less/theme-variable.less"/>
    <script src="//cdnjs.cloudflare.com/ajax/libs/less.js/3.9.0/less.min.js" ></script>

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

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