Comments (6)
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.
Before the build step in Docker you need to run temple generate
it's copying over your --watch
mode templates.
from templ.
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.
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.
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.
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 excessiveI 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 runstempl 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)
- css: rotation transform getting sanitized HOT 5
- vscode: Inconsistent syntax highlighting in vscode. HOT 3
- tests: templ generate exits with 0 when there are errors HOT 6
- Error Installing on windows 10 HOT 2
- Lack of proper CSS handling? HOT 1
- vscode: Multi-line Go control blocks are not correctly syntax highlighted HOT 4
- cmd: templ generate with watch can generate corrupted Go files, because of race condition with fsnotify WRITE events HOT 6
- Is there any way to generate raw attributes without any escaping? HOT 3
- generator: HTML Entites not rendering HOT 2
- LSP Server dont attach to Nvim HOT 2
- generator: Add support for templ type methods
- vscode: HTML attribute conditionals do not have proper syntax highlighting HOT 3
- Feature request: Reduce verbose output to terminal HOT 2
- Generate output differs between windows and linux HOT 2
- Formatter messing up script formatting HOT 10
- Formatter break long lines incorrectly HOT 6
- docs: In gin the status passed to the HTML func is always overwritten with 200 HOT 5
- Concurrent map read and write error HOT 3
- Is a component nested inside another component possible? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from templ.