/helper-content/css_reloading.md

https://github.com/bhauman/figwheel-main · Markdown · 74 lines · 55 code · 19 blank · 0 comment · 0 complexity · 4b15bba0792b5cdae7c63988b9412097 MD5 · raw file

  1. # Live CSS reloading
  2. <div class="lead-in">Figwheel will hot reload your CSS files as you edit them.</div>
  3. You need to do four things for this to work:
  4. * ensure that you are providing your own [HTML host page][host-page]
  5. * include a link to your CSS in your host page HTML
  6. * ensure your CSS is in a `public` directory on the classpath
  7. * configure the [`:css-dirs` config option][css-dirs]
  8. ## Including link to CSS file
  9. Include a link tag to your CSS on your [HTML host page][host-page].
  10. ```html
  11. <!DOCTYPE html>
  12. <html>
  13. <head>
  14. <meta charset="UTF-8">
  15. <!-- we are including the CSS here -->
  16. <link href="css/style.css" rel="stylesheet" type="text/css">
  17. </head>
  18. <body>
  19. <div id="app">
  20. </div>
  21. <script src="cljs-out/dev-main.js" type="text/javascript"></script>
  22. </body>
  23. </html>
  24. ```
  25. ## Ensuring your CSS file can be served
  26. The above example will work if you place your CSS file in a
  27. `public/css` directory on the classpath. Since the `resources`
  28. directory is normally on the classpath by convention we can place our
  29. CSS files `resources/public/css`.
  30. ## Tell Figwheel to watch and reload CSS
  31. You will use the [`:css-dirs` config key][css-dirs] to tell Figwheel
  32. to which directories to watch for CSS file changes.
  33. You can do this one of two ways: in the **build file** or in the
  34. `figwheel-main.edn` file.
  35. As and example let's assuming a `dev.cljs.edn` build file. You can add
  36. `:css-dirs` config to the metadata in the build file like so:
  37. ```clojure
  38. ^{:css-dirs ["resources/public/css"]}
  39. {:main example.core}
  40. ```
  41. Or you can set it for all builds and compiles in the `figwheel-main.edn`:
  42. ```clojure
  43. {:css-dirs ["resources/public/css"]
  44. ;; rest of the config
  45. }
  46. ```
  47. Then you restart your build:
  48. ```shell
  49. clojure -m figwheel.main -b dev -r
  50. ```
  51. Now you should be able to edit and save the
  52. `resources/public/css/style.css` file and see the changes rendered
  53. live in your application.
  54. [css-dirs]: //figwheel.org/config-options#css-dirs
  55. [host-page]: //figwheel.org/docs/your_own_page