Code Monkey home page Code Monkey logo

Comments (6)

IcelandicIcecream avatar IcelandicIcecream commented on June 17, 2024

Adding to this:
Here's the error I'm getting:
2024-02-09T17:08:46Z ERR server/server.go:23 > 200 | GET: '/' -- templ: failed to cache strings: templ: failed to open /app/views/layout/base_templ.txt: open /app/views/layout/base_templ.txt: no such file or directory pid=1

EDIT: I had to port over my views folder for the .txt files to be there in my dockerfile. I don't know if this is intentional. But perhaps this can be added in the documentation for projects with components in nested folders?

from templ.

joerdav avatar joerdav commented on June 17, 2024

Before the build step in Docker you need to run temple generate it's copying over your --watch mode templates.

from templ.

IcelandicIcecream avatar IcelandicIcecream commented on June 17, 2024

Before the build step in Docker you need to run temple generate it's copying over your --watch mode templates.

Oh I see. So I would need to build and install templ in my docker image, and then templ generate to get the txt files during my build stage? Is this the best way? seems a bit excessive haha Also, for some reason, when I do templ generate.. It doesn't generate the txt files anymore. Only templ generate --watch does and it deletes the txt file when I stop it

from templ.

joerdav avatar joerdav commented on June 17, 2024

The txt files are only relevant for dev mode. When you run templ generate on it's own you get the production templates. That's why I'd recommend a templ generate in your build process, just incase you forgot to do a prod build.

from templ.

alehechka avatar alehechka commented on June 17, 2024

So I would need to build and install templ in my docker image, and then templ generate to get the txt files during my build stage? Is this the best way? seems a bit excessive

I feel like it's better to do it this way imo. When I personally use templ I gitignore all of the Go code that templ generates (all *_templ.go files) and the docker image runs templ generate everytime so it always has the most up-to-date code. This also will fail the docker build if templ throws an error during generation which is better because it ensures the templ code I pushed is still valid.

Here's an snippet from one of my projects:

# BASE IMAGES
FROM --platform=$BUILDPLATFORM golang:1.21 as go-base

# GENERATE TEMPL

FROM go-base as templ-builder

WORKDIR /app

COPY go.mod .

# install templ version that go.mod is using
RUN go install github.com/a-h/templ/cmd/templ@$(go list -m -f '{{ .Version }}' github.com/a-h/templ)

COPY web/templ web/templ

RUN templ generate --path=web/templ

from templ.

IcelandicIcecream avatar IcelandicIcecream commented on June 17, 2024

So I would need to build and install templ in my docker image, and then templ generate to get the txt files during my build stage? Is this the best way? seems a bit excessive

I feel like it's better to do it this way imo. When I personally use templ I gitignore all of the Go code that templ generates (all *_templ.go files) and the docker image runs templ generate everytime so it always has the most up-to-date code. This also will fail the docker build if templ throws an error during generation which is better because it ensures the templ code I pushed is still valid.

Here's an snippet from one of my projects:

# BASE IMAGES
FROM --platform=$BUILDPLATFORM golang:1.21 as go-base

# GENERATE TEMPL

FROM go-base as templ-builder

WORKDIR /app

COPY go.mod .

# install templ version that go.mod is using
RUN go install github.com/a-h/templ/cmd/templ@$(go list -m -f '{{ .Version }}' github.com/a-h/templ)

COPY web/templ web/templ

RUN templ generate --path=web/templ

Awesome thanks for this, I'll use it as a reference for mine. Having thought about it, it does make sense to do it on build to simplify the CI/CD process

from templ.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.