run sass in development mode;

document how to install sass better
This commit is contained in:
iacore
2024-02-18 21:12:15 +00:00
parent c6ce7235ac
commit 8dd88fbf7a
2 changed files with 28 additions and 9 deletions
+9 -9
View File
@@ -33,20 +33,20 @@ To deploy PixivFE using Docker or the compiled binary, see the [Hosting PixivFE]
**Requirements:**
- [pnpm](https://pnpm.io/installation) (to install Sass)
- [go](https://go.dev/doc/install) (to build PixivFE from source)
- [Go](https://go.dev/doc/install) (to build PixivFE from source)
- [Sass](https://github.com/sass/dart-sass/) (will be run by PixivFE in development mode)
To install Dart Sass, you can choose any of the following methods.
- use system package manager (usually called `dart-sass`)
- download executable from [the official release page](https://github.com/sass/dart-sass/releases)
- `pnpm i -g sass`
```bash
# Clone the PixivFE repository
git clone https://codeberg.org/VnPower/PixivFE.git && cd PixivFE
# Install Sass globally using pnpm
pnpm i -g sass
# Compile styles using Sass and watch for changes
sass --watch ./views/css
# Run in PixivFE in development mode (templates reload automatically)
# Run in PixivFE in development mode (styles and templates reload automatically)
PIXIVFE_DEV=1 <other_environment_variables> go run .
```
+19
View File
@@ -6,7 +6,11 @@ import (
"log"
"net"
"net/http"
"os"
"os/exec"
"runtime"
"strings"
"syscall"
"time"
config "codeberg.org/vnpower/pixivfe/v2/core/config"
@@ -205,6 +209,21 @@ func main() {
proxy.Get("/s.pximg.net/*", pages.SPximgProxy)
proxy.Get("/ugoira.com/*", pages.UgoiraProxy)
// run sass when in development mode
if config.GlobalServerConfig.InDevelopment {
go func() {
cmd := exec.Command("sass", "--watch", "views/css")
cmd.Stdout = os.Stderr // heh. (sass quirk)
cmd.Stderr = os.Stderr
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pdeathsig: syscall.SIGHUP}
runtime.LockOSThread() // O.O https://github.com/golang/go/issues/27505
err := cmd.Run()
if err != nil {
log.Println(fmt.Errorf("when running sass: %w", err))
}
}()
}
// Listen
if config.GlobalServerConfig.UnixSocket != "" {
ln, err := net.Listen("unix", config.GlobalServerConfig.UnixSocket)