【问题标题】:Yesod css - not in scope variableYesod css - 不在范围变量中
【发布时间】:2015-10-13 22:41:15
【问题描述】:

我从模板初始化 Yesod 项目。 尝试在 Foundation.hs 更改 css 变量时出现错误

$ stack new s1 yesod-simple
$ cd s1
$ mv static/css/bootstrap.css static/css/style.css

更改Foundation.hs

pc <- widgetToPageContent $ do
    addStylesheet $ StaticR css_bootstrap_css
    $(widgetFile "default-layout")

     pc <- widgetToPageContent $ do
         addStylesheet $ StaticR css_style_css
         $(widgetFile "default-layout")

$ stack build
...
[4 of 8] Compiling Foundation       ( Foundation.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Foundation.o )

Foundation.hs:64:37: Not in scope: ‘css_style_css’

但据我所知,在编译时 css_style_css 应该会自动出现。 我做错了什么?如果我们需要在默认布局中添加几个 css 文件,我该怎么办?

【问题讨论】:

    标签: haskell yesod


    【解决方案1】:

    来自Yesod tutorial

    每当您修改静态文件夹时,触摸 StaticFiles.hs 即可 应该不错。

    所以,在控制台中运行这个命令:

    touch Settings/StaticFiles.hs

    需要编译StaticFiles.hs 文件才能获得css_style_css 定义。如果你修改你的静态文件夹,这个文件与文件夹内容不同步,但 GHC/Stack 没有办法找出来。

    【讨论】:

      【解决方案2】:
      1. 打开您的 Cabal 文件
      2. 查找块:
      if flag(dev) || flag(library-only)
          cpp-options:   -DDEVELOPMENT
          ghc-options:   -Wall -fwarn-tabs -O0
      else
          ghc-options:   -Wall -fwarn-tabs -O2
      

      并将 -fforce-recomp 添加到 ghc-options 以获取所需的行。

      【讨论】:

      • 在最近的模板中,这必须添加到 package.yaml 文件中,因为 cabal 文件是自动生成的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-08
      • 1970-01-01
      相关资源
      最近更新 更多