Skip to content

Commit

Permalink
Build frontend with Vite
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Jul 13, 2023
1 parent eec45b4 commit c7fd0d7
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ cpu.out
/public/js
/public/css
/public/fonts
/public/img/webpack
/public/img/bundled
/vendor
/web_src/fomantic/node_modules
/web_src/fomantic/build/*
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ cpu.out
/public/js
/public/css
/public/fonts
/public/img/webpack
/public/img/bundled
/vendor
/web_src/fomantic/node_modules
/web_src/fomantic/build/*
Expand Down
30 changes: 15 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/m

FOMANTIC_WORK_DIR := web_src/fomantic

WEBPACK_SOURCES := $(shell find web_src/js web_src/css -type f)
WEBPACK_CONFIGS := webpack.config.js
WEBPACK_DEST := public/js/index.js public/css/index.css
WEBPACK_DEST_ENTRIES := public/js public/css public/fonts public/img/webpack
VITE_SOURCES := $(shell find web_src/js web_src/css -type f)
VITE_CONFIGS := vite.config.js
VITE_DEST := public/js/index.js public/css/index.css
VITE_DEST_ENTRIES := public/js public/css public/fonts public/img/bundled

BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
Expand Down Expand Up @@ -228,7 +228,7 @@ help:
@echo " - test-e2e[\#TestSpecificName] test end to end using playwright"
@echo " - update-js update js dependencies"
@echo " - update-py update py dependencies"
@echo " - webpack build webpack files"
@echo " - vite build vite files"
@echo " - svg build svg files"
@echo " - fomantic build fomantic files"
@echo " - generate run \"go generate\""
Expand Down Expand Up @@ -273,7 +273,7 @@ node-check:

.PHONY: clean-all
clean-all: clean
rm -rf $(WEBPACK_DEST_ENTRIES) node_modules
rm -rf $(VITE_DEST_ENTRIES) node_modules

.PHONY: clean
clean:
Expand Down Expand Up @@ -434,8 +434,8 @@ watch:

.PHONY: watch-frontend
watch-frontend: node-check node_modules
@rm -rf $(WEBPACK_DEST_ENTRIES)
NODE_ENV=development npx webpack --watch --progress
@rm -rf $(VITE_DEST_ENTRIES)
NODE_ENV=development npx vite build --watch

.PHONY: watch-backend
watch-backend: go-check
Expand Down Expand Up @@ -806,7 +806,7 @@ install: $(wildcard *.go)
build: frontend backend

.PHONY: frontend
frontend: $(WEBPACK_DEST)
frontend: $(VITE_DEST)

.PHONY: backend
backend: go-check generate-backend $(EXECUTABLE)
Expand Down Expand Up @@ -952,14 +952,14 @@ fomantic:
$(SED_INPLACE) -e 's/\r//g' $(FOMANTIC_WORK_DIR)/build/semantic.css $(FOMANTIC_WORK_DIR)/build/semantic.js
rm -f $(FOMANTIC_WORK_DIR)/build/*.min.*

.PHONY: webpack
webpack: $(WEBPACK_DEST)
.PHONY: vite
vite: $(VITE_DEST)

$(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json
$(VITE_DEST): $(VITE_SOURCES) $(VITE_CONFIGS) package-lock.json
@$(MAKE) -s node-check node_modules
rm -rf $(WEBPACK_DEST_ENTRIES)
npx webpack
@touch $(WEBPACK_DEST)
rm -rf $(VITE_DEST_ENTRIES)
npx vite build
@touch $(VITE_DEST)

.PHONY: svg
svg: node-check | node_modules
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/installation/from-source.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ If pre-built frontend files are present it is possible to only build the backend
TAGS="bindata" make backend
```

Webpack source maps are by default enabled in development builds and disabled in production builds. They can be enabled by setting the `ENABLE_SOURCEMAP=true` environment variable.
Webpack source maps are by default enabled in development builds and disabled in production builds. They can be enabled by setting the `VITE_ENABLE_SOURCEMAP=true` environment variable.

## Test

Expand Down
Loading

0 comments on commit c7fd0d7

Please sign in to comment.