Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. ---
  2. title: Compiling Sass Themes
  3. order: 4
  4. layout: page
  5. ---
  6. [[themes.compiling]]
  7. = Compiling Sass Themes
  8. Sass themes must be compiled to CSS understood by browsers. Compilation can be
  9. done with the Vaadin Sass Compiler, which you can run in Eclipse, Maven, or it
  10. can be run on-the-fly when the application is loaded in the browser. You can
  11. also use any other Sass compiler.
  12. [[themes.compiling.on-the-fly]]
  13. == Compiling On the Fly
  14. The easiest way to develop Sass themes is to compile them at runtime, when the page is loaded.
  15. The Vaadin servlet does this automatically if a compiled theme CSS file is not found from the theme folder.
  16. You need to have the SCSS source files placed in the theme folder.
  17. The theme is compiled when the [filename]#styles.css# is first requested from the server.
  18. If you edit the Sass theme, it is recompiled the next time you reload the page.
  19. The on-the-fly compilation takes a bit time, so it is only available when the
  20. Vaadin servlet is in the development mode, as described in
  21. <<dummy/../../../framework/application/application-environment#application.environment.parameters,"Other
  22. Servlet Configuration Parameters">>. Also, it requires the theme compiler and
  23. all its dependencies to be in the class path of the servlet. At least for
  24. production, you must compile the theme to CSS, as described next.
  25. NOTE: If the on-the-fly compilation does not seem to work, ensure that your build script has not generated a pre-compiled CSS file.
  26. If [filename]#styles.css# file is found the servlet, the compilation is skipped.
  27. Delete such an existing [filename]#styles.css# file and disable theme compilation temporarily.
  28. [[themes.compiling.eclipse]]
  29. == Compiling in Eclipse
  30. If using Eclipse and the Vaadin Plugin for Eclipse, its project wizard creates a
  31. Sass theme. It includes [menuchoice]#Compile Theme# command in the toolbar to
  32. compile the project theme to CSS. Another command compiles also the widget set.
  33. [[figure.themes.compiling.eclipse]]
  34. .Compiling Sass Theme
  35. image::img/eclipse-theme-compiler.png[]
  36. The [filename]#WebContent/VAADIN/mytheme/styles.scss# and any Sass sources
  37. included by it are compiled to [filename]#styles.css#.
  38. [[themes.compiling.maven]]
  39. == Compiling with Maven
  40. To compile the themes with Maven, you need to include the built-in themes as a
  41. dependency:
  42. [source, xml]
  43. ----
  44. ...
  45. <dependencies>
  46. ...
  47. <dependency>
  48. <groupId>com.vaadin</groupId>
  49. <artifactId>vaadin-themes</artifactId>
  50. <version>${vaadin.version}</version>
  51. </dependency>
  52. </dependencies>
  53. ...
  54. ----
  55. This is automatically included at least in the
  56. [literal]#++vaadin-archetype-application++# archetype for Vaadin applications.
  57. The actual theme compilation is most conveniently done by the Vaadin Maven
  58. Plugin with [literal]#++update-theme++# and [literal]#++compile-theme++# goals.
  59. [source, xml]
  60. ----
  61. ...
  62. <plugin>
  63. <groupId>com.vaadin</groupId>
  64. <artifactId>vaadin-maven-plugin</artifactId>
  65. ...
  66. <executions>
  67. <execution>
  68. ...
  69. <goals>
  70. <goal>clean</goal>
  71. <goal>resources</goal>
  72. <goal>update-theme</goal>
  73. <goal>update-widgetset</goal>
  74. <goal>compile-theme</goal>
  75. <goal>compile</goal>
  76. </goals>
  77. </execution>
  78. </executions>
  79. ----
  80. Once these are in place, the theme is compiled as part of relevant lifecycle
  81. phases, such as [literal]#++package++#.
  82. [subs="normal"]
  83. ----
  84. [command]#mvn# [parameter]#package#
  85. ----
  86. You can also compile just the theme with the [package]#compile-theme# goal:
  87. [subs="normal"]
  88. ----
  89. [command]#mvn# [parameter]#vaadin:compile-theme#
  90. ----
  91. ifdef::web[]
  92. [[themes.compiling.command-line]]
  93. == Compiling in Command-line
  94. You can compile Sass style sheets to CSS either with the Vaadin Sass compiler or
  95. the standard one. The [filename]#styles.css# of a custom theme should be the
  96. compilation target. When compiled before deployment, the source files do not
  97. need to be in the theme folder.
  98. You can run the Vaadin Sass compiler in a theme folder as follows:
  99. [subs="normal"]
  100. ----
  101. [command]#java# [parameter]#-cp# [replaceable]#'../../../WEB-INF/lib/*'# com.vaadin.sass.SassCompiler styles.scss styles.css
  102. ----
  103. The [parameter]#-cp# parameter should point to the class path where the Vaadin
  104. Sass Compiler and theme JARs are located. In the above example, they are assumed
  105. to be located in the [filename]#WEB-INF/lib# folder of the web application. If
  106. you have loaded the Vaadin libraries using Ivy, as is the case with projects
  107. created with the Vaadin Plugin for Eclipse, the Vaadin libraries are stored in
  108. Ivy's local repository. Its folder hierarchy is somewhat scattered, so we
  109. recommend that you retrieve the libraries to a single folder. We recommend using
  110. an Ant script as is described next.
  111. endif::web[]
  112. [[themes.compiling.ant]]
  113. == Compiling with Ant
  114. With Apache Ant, you can easily resolve the dependencies with Ivy and compile
  115. the theme with the Theme Compiler included in Vaadin as follows. This build step
  116. can be conveniently included in a WAR build script.
  117. Start with the following configuration:
  118. [source, xml]
  119. ----
  120. <project xmlns:ivy="antlib:org.apache.ivy.ant"
  121. name="My Project" basedir="../"
  122. default="package-war">
  123. <target name="configure">
  124. <!-- Where project source files are located -->
  125. <property name="src-location" value="src" />
  126. ... other project build definitions ...
  127. <!-- Name of the theme -->
  128. <property name="theme" value="book-examples"/>
  129. <!-- Compilation result directory -->
  130. <property name="result" value="build/result"/>
  131. </target>
  132. <!-- Initialize build -->
  133. <target name="init" depends="configure">
  134. <!-- Construct and check classpath -->
  135. <path id="compile.classpath">
  136. <!-- Source code to be compiled -->
  137. <pathelement path="${src-location}" />
  138. <!-- Vaadin libraries and dependencies -->
  139. <fileset dir="${result}/lib">
  140. <include name="*.jar"/>
  141. </fileset>
  142. </path>
  143. <mkdir dir="${result}"/>
  144. </target>
  145. ----
  146. You should first resolve all Vaadin libraries to a single directory, which you
  147. can use for deployment, but also for theme compilation.
  148. ----
  149. <target name="resolve" depends="init">
  150. <ivy:retrieve
  151. pattern="${result}/lib/[module]-[type]-[artifact]-[revision].[ext]"/>
  152. </target>
  153. ----
  154. Then, you can compile the theme as follows:
  155. ----
  156. <!-- Compile theme -->
  157. <target name="compile-theme"
  158. depends="init, resolve">
  159. <delete dir="${result}/VAADIN/themes/${theme}"/>
  160. <mkdir dir="${result}/VAADIN/themes/${theme}"/>
  161. <java classname="com.vaadin.sass.SassCompiler"
  162. fork="true">
  163. <classpath>
  164. <path refid="compile.classpath"/>
  165. </classpath>
  166. <arg value="WebContent/VAADIN/themes/${theme}/styles.scss"/>
  167. <arg value="${result}/VAADIN/themes/${theme}/styles.css"/>
  168. </java>
  169. <!-- Copy theme resources -->
  170. <copy todir="${result}/VAADIN/themes/${theme}">
  171. <fileset dir="WebContent/VAADIN/themes/${theme}">
  172. <exclude name="**/*.scss"/>
  173. </fileset>
  174. </copy>
  175. </target>
  176. </project>
  177. ----