1

我有一个简单的 Yesod 项目,其通常的目录结构如下:

./Main.hs
./Foundation.hs
./Handler/Home.hs
./Handler/... etc
./config/routes
./templates/home.hamlet
./templates/default-layout.hamlet
./templates/default-layout-wrapper.hamlet
./templates/default-layout-wrapper.cassius
...

我正在尝试使用堆栈构建这个项目,通常Main.hs程序位于app目录下。

我试图将所有 Yesod 结构放在app目录下(app目录在.上面)。

该项目的 cabal 文件如下所示:

executable proj-web01-exe
  hs-source-dirs:      app
  main-is:             Main.hs
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  build-depends:       base, bytestring, split, filepath
                     , stm, data-default, text, conduit, conduit-extra
                     , containers, resourcet, blaze-html, blaze-markup
                     , shakespeare, yesod, yesod-static
                     , proj-web01
  default-language:    Haskell2010

现在,当我尝试时stack build,我收到以下错误消息:

[1 of 6] Compiling Foundation       ( app/Foundation.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/proj-web01-exe/proj-web01-exe-tmp/Foundation.o )

/home/me/proj-web01/app/Foundation.hs:46:35:
    Exception when trying to run compile-time code:
      Called widgetFileNoReload on "default-layout", but no templates were found.
    Code: widgetFileNoReload (def) "default-layout"
    In the splice: $(widgetFileNoReload def "default-layout")

--  While building package proj-web01-0.1.0.0 using:
      /home/me/.stack/setup-exe-cache/x86_64-linux/setup-Simple-Cabal-1.22.5.0-ghc-7.10.3 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.22.5.0 build lib:proj-web01 exe:proj-web01-exe --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

widgetFileNoReload不知道在哪里可以找到app/templates目录中的“默认布局”文件。

我的问题:我应该以不同的方式编写 cabal 文件,还是应该将模板、处理程序...文件夹放在其他地方(例如在 src 中)?使用堆栈时最自然的目录结构是什么?或者如何设置堆栈参数(cabal 和 yaml 文件)以适应通常的 Yesod 目录结构?

4

1 回答 1

1

如果您使用标准的 Yesod 脚手架,它应该可以毫无问题地编译 Stack(事实上,我现在正在这样做)。在您熟悉设置之前,我建议您不要移动脚手架文件。如果您真的想移动源文件,我建议您将模板保留在原始位置。

于 2016-01-13T14:08:55.563 回答