Liferay 6.2 Ant Build - 升级 SCSS 编译器

Liferay 6.2 Ant Build - Upgrade SCSS compiler

我目前正在开发 liferay 主题,但是在编译其中一个 SCSS 文件时,出现以下错误:

 [java] Sass::SyntaxError: Invalid CSS after "  @each $key": expected "in", was ", $num in $map {"
 [java]            expected at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:1147
 [java]            expected at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:1084
 [java]                tok! at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:1079
 [java]      each_directive at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:248
 [java]                send at org/jruby/RubyKernel.java:2093
 [java]   special_directive at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:174
 [java]           directive at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:146
 [java]         block_child at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:553
 [java]      block_contents at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:545
 [java]               block at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:534
 [java]     mixin_directive at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:186
 [java]                send at org/jruby/RubyKernel.java:2093
 [java]   special_directive at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:174
 [java]           directive at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:146
 [java]         block_child at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:552
 [java]      block_contents at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:542
 [java]          stylesheet at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:82
 [java]               parse at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/scss/parser.rb:27
 [java]            _to_tree at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/engine.rb:342
 [java]             to_tree at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/engine.rb:272
 [java]        visit_import at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:225
 [java]                send at org/jruby/RubyKernel.java:2097
 [java]               visit at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/base.rb:37
 [java]               visit at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:100
 [java]        visit_import at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:227
 [java]             collect at org/jruby/RubyArray.java:2318
 [java]        visit_import at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:227
 [java]                send at org/jruby/RubyKernel.java:2097
 [java]               visit at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/base.rb:37
 [java]               visit at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:100
 [java]      visit_children at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/base.rb:53
 [java]             collect at org/jruby/RubyArray.java:2318
 [java]      visit_children at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/base.rb:53
 [java]      visit_children at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:109
 [java]    with_environment at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:121
 [java]      visit_children at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:108
 [java]               visit at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/base.rb:37
 [java]          visit_rule at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:320
 [java]                send at org/jruby/RubyKernel.java:2097
 [java]               visit at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/base.rb:37
 [java]               visit at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:100
 [java]      visit_children at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/base.rb:53
 [java]             collect at org/jruby/RubyArray.java:2318
 [java]      visit_children at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/base.rb:53
 [java]      visit_children at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:109
 [java]    with_environment at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:121
 [java]      visit_children at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:108
 [java]               visit at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/base.rb:37
 [java]          visit_root at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:128
 [java]                send at org/jruby/RubyKernel.java:2097
 [java]               visit at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/base.rb:37
 [java]               visit at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:100
 [java]                send at org/jruby/RubyKernel.java:2097
 [java]               visit at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/visitors/perform.rb:7
 [java]              render at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/tree/root_node.rb:20
 [java]             _render at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/engine.rb:315
 [java]              render at C:/Users/BARRYC~1/AppData/Local/Temp/liferay/ruby/gems/sass-3.2.12/lib/sass/../sass/engine.rb:262
 [java]              (root) at <script>:48
 [java] Exception in thread "main" org.jruby.embed.EvalFailedException: (SyntaxError) Invalid CSS after "  @each $key": expected "in", was ", $num in $map {"
 [java]     at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:127)
 [java]     at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1231)
 [java]     at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1224)
 [java]     at com.liferay.portal.scripting.ruby.RubyExecutor.doEval(RubyExecutor.java:189)
 [java]     at com.liferay.portal.scripting.ruby.RubyExecutor.eval(RubyExecutor.java:229)
 [java]     at com.liferay.portal.scripting.ruby.RubyExecutor.eval(RubyExecutor.java:129)
 [java]     at com.liferay.portal.tools.SassToCssBuilder._parseSassFile(SassToCssBuilder.java:288)
 [java]     at com.liferay.portal.tools.SassToCssBuilder._parseSassDirectory(SassToCssBuilder.java:247)
 [java]     at com.liferay.portal.tools.SassToCssBuilder.<init>(SassToCssBuilder.java:139)
 [java]     at com.liferay.portal.tools.SassToCssBuilder.main(SassToCssBuilder.java:93)
 [java] Caused by: org.jruby.exceptions.RaiseException: (SyntaxError) Invalid CSS after "  @each $key": expected "in", was ", $num in $map {"
 [java] Unable to parse /css/aui.css
 [java] Java Result: 1

有问题的文件(aui.css):

$FontAwesomePath: "aui/font-awesome-5/font" !default;

//@import "aui/alloy-font-awesome/scss/variables";
//@import "aui/alloy-font-awesome/scss/mixins-alloy";
//@import "aui/alloy-font-awesome/scss/path-alloy";

.aui {
    @import "aui_variables";

    $iconSpritePath: '../images/aui/glyphicons-halflings.png' !default;
    $iconWhiteSpritePath: '../images/aui/glyphicons-halflings-white.png' !default;

    //@import "aui/bootstrap"; // Remove >> Bootstrap 2.3.2
    @import "aui/variables-alloy";
    @import "aui/variables";
    @import "aui/bs4/bootstrap"; // Add >> Bootstrap 3.5
}

我正在使用 Liferay 6.2 EE GA1,我读到的这个错误可能可以通过升级 SCSS 编译器 (ruby gem) 来修复。但是,我什至不知道如何处理。它正在使用 ant 生成器 (build.xml)。

如果我能修复上面的错误,或者升级编译器(或两者都升级?)那就太好了!

如果要手动升级SASS版本,可以重新设置scripting.jruby.load.paths属性。请看一下6.2 Portal Properties。因此,您没有使用类路径或 java.io.tmpdir 而是使用不同的文件夹。但是,我没有对此进行测试,并且此升级可能会导致其他问题失败(您还需要有关 CI 构建的概念)。

我成功将 Liferay 6.2 升级到 bootstrap 4 :

  1. 您需要转到 tomcat/webapps/ROOT/WEB-INF/lib 并删除 ruby-gems.jar

  2. 下载com.liferay.ruby.gems-1.0.1.jar(网上搜索)放到上面的lib文件夹下

  3. 修改您的门户-ext.properties 并添加:

#jruby fix
scripting.jruby.load.paths=\
classpath:/META-INF/jruby.home/lib/ruby/site_ruby/1.8,\
classpath:/META-INF/jruby.home/lib/ruby/site_ruby/shared,\
classpath:/gems/chunky_png-1.3.5/lib,\
classpath:/gems/compass-1.0.1/lib,\
classpath:/gems/compass-core-1.0.3/lib,\
classpath:/gems/multi_json-1.11.3/lib,\
classpath:/gems/fssm-0.2.9/lib,\
classpath:/gems/sass-3.4.22/lib,\
${java.io.tmpdir}/liferay/ruby/gems/chunky_png-1.3.5/lib,\
${java.io.tmpdir}/liferay/ruby/gems/compass-1.0.1/lib,\
${java.io.tmpdir}/liferay/ruby/gems/fssm-0.2.9/lib,\
${java.io.tmpdir}/liferay/ruby/gems/sass-3.4.22/lib
  1. 清理 tomcat 的工作目录和临时目录,然后重新启动 Liferay

我也稍微更改了主题..将所有 aui.css、main.css(和导入)文件更改为 scss 文件(因为它们不是真正的 css) 并使用 webpack 4 编译它们(比 Ruby 快多了)。