Skip to content

Commit cbceca4

Browse files
committed
move CSS build to webpack
- added new 'make webpack' target - deprecated 'make js' and 'make css' - extend webpack config to load the less files - updated docs I had to rename the source file of `arc-green.less` to avoid generating a useless JS entrypoint via webpack-fix-style-only-entries which would not work with different source/destination filenames. I hear that there should be cleaner solutions possible once we upgrade to Webpack 5.
1 parent 3c8a5d8 commit cbceca4

File tree

10 files changed

+88
-425
lines changed

10 files changed

+88
-425
lines changed

.drone.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ steps:
1515
pull: always
1616
image: node:10 # this step is kept at the lowest version of node that we support
1717
commands:
18-
- make css js
18+
- make webpack
1919

2020
- name: build-without-gcc
2121
pull: always

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ insert_final_newline = true
77
trim_trailing_whitespace = true
88
end_of_line = lf
99

10+
[*.md]
11+
trim_trailing_whitespace = false
12+
1013
[*.go]
1114
indent_style = tab
1215
indent_size = 8

CONTRIBUTING.md

+1-9
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,7 @@ included in the next released version.
114114

115115
## Building Gitea
116116

117-
Generally, the go build tools are installed as-needed in the `Makefile`.
118-
An exception are the tools to build the CSS, JS and images.
119-
120-
- To build CSS and JS: Install [Node.js](https://nodejs.org/en/download/package-manager) at version 10.0 or above
121-
with `npm` and then run `npm install`, `make css` and `make js`.
122-
- To build Images: ImageMagick, inkscape and zopflipng binaries must be
123-
available in your `PATH` to run `make generate-images`.
124-
125-
For more details on how to generate files, build and test Gitea, see the [hacking instructions](https://docs.gitea.io/en-us/hacking-on-gitea/)
117+
See the [hacking instructions](https://docs.gitea.io/en-us/hacking-on-gitea/).
126118

127119
## Code review
128120

Makefile

+21-26
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@ LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(G
4646
PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations/migration-test,$(filter-out code.gitea.io/gitea/integrations,$(shell GO111MODULE=on $(GO) list -mod=vendor ./... | grep -v /vendor/)))
4747

4848
GO_SOURCES ?= $(shell find . -name "*.go" -type f)
49-
JS_SOURCES ?= $(shell find web_src/js web_src/css -type f)
50-
CSS_SOURCES ?= $(shell find web_src/less -type f)
49+
WEBPACK_SOURCES ?= $(shell find web_src/js web_src/css web_src/less -type f)
5150

52-
JS_DEST := public/js/index.js
53-
CSS_DEST := public/css/index.css
51+
WEBPACK_DEST := public/js/index.js public/css/index.css
5452
BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
5553
BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
5654

57-
JS_DEST_DIR := public/js
58-
CSS_DEST_DIR := public/css
55+
WEBPACK_DEST_DIRS := public/js public/css
5956
FOMANTIC_DEST_DIR := public/fomantic
6057

6158
TAGS ?=
@@ -87,9 +84,6 @@ TEST_MSSQL_DBNAME ?= gitea
8784
TEST_MSSQL_USERNAME ?= sa
8885
TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
8986

90-
# $(call strip-suffix,filename)
91-
strip-suffix = $(firstword $(subst ., ,$(1)))
92-
9387
.PHONY: all
9488
all: build
9589

@@ -102,10 +96,9 @@ help:
10296
@echo " - build creates the entire project"
10397
@echo " - clean delete integration files and build files but not css and js files"
10498
@echo " - clean-all delete all generated files (integration test, build, css and js files)"
105-
@echo " - css rebuild only css files"
106-
@echo " - js rebuild only js files"
99+
@echo " - webpack rebuild only js and css files"
107100
@echo " - fomantic rebuild fomantic-ui files"
108-
@echo " - generate run \"make fomantic css js\" and \"go generate\""
101+
@echo " - generate run \"make fomantic webpack\" and \"go generate\""
109102
@echo " - fmt format the code"
110103
@echo " - generate-swagger generate the swagger spec from code comments"
111104
@echo " - swagger-validate check if the swagger spec is valid"
@@ -141,7 +134,7 @@ node-check:
141134

142135
.PHONY: clean-all
143136
clean-all: clean
144-
rm -rf $(JS_DEST_DIR) $(CSS_DEST_DIR) $(FOMANTIC_DEST_DIR)
137+
rm -rf $(WEBPACK_DEST_DIRS) $(FOMANTIC_DEST_DIR)
145138

146139
.PHONY: clean
147140
clean:
@@ -161,7 +154,7 @@ vet:
161154
$(GO) vet $(PACKAGES)
162155

163156
.PHONY: generate
164-
generate: fomantic js css
157+
generate: fomantic webpack
165158
GO111MODULE=on $(GO) generate -mod=vendor -tags '$(TAGS)' $(PACKAGES)
166159

167160
.PHONY: generate-swagger
@@ -481,6 +474,7 @@ release-compress:
481474

482475
node_modules: package-lock.json
483476
npm install --no-save
477+
@touch node_modules
484478

485479
.PHONY: npm-update
486480
npm-update: node-check | node_modules
@@ -489,12 +483,14 @@ npm-update: node-check | node_modules
489483
npm install --package-lock
490484

491485
.PHONY: js
492-
js: node-check $(JS_DEST)
486+
js:
487+
@echo "'make js' is deprecated, please use 'make webpack'"
488+
$(MAKE) webpack
493489

494-
$(JS_DEST): $(JS_SOURCES) | node_modules
495-
npx eslint web_src/js webpack.config.js
496-
npx webpack --hide-modules --display-entrypoints=false
497-
@touch $(JS_DEST)
490+
.PHONY: css
491+
css:
492+
@echo "'make css' is deprecated, please use 'make webpack'"
493+
$(MAKE) webpack
498494

499495
.PHONY: fomantic
500496
fomantic: node-check $(FOMANTIC_DEST_DIR)
@@ -505,15 +501,14 @@ $(FOMANTIC_DEST_DIR): semantic.json web_src/fomantic/theme.config.less | node_mo
505501
npx gulp -f node_modules/fomantic-ui/gulpfile.js build
506502
@touch $(FOMANTIC_DEST_DIR)
507503

508-
.PHONY: css
509-
css: node-check $(CSS_DEST)
504+
.PHONY: webpack
505+
webpack: node-check $(WEBPACK_DEST)
510506

511-
$(CSS_DEST): $(CSS_SOURCES) | node_modules
507+
$(WEBPACK_DEST): $(WEBPACK_SOURCES) | node_modules
508+
npx eslint web_src/js webpack.config.js
512509
npx stylelint web_src/less
513-
npx lessc web_src/less/index.less public/css/index.css
514-
$(foreach file, $(filter-out web_src/less/themes/_base.less, $(wildcard web_src/less/themes/*)),npx lessc web_src/less/themes/$(notdir $(file)) > public/css/theme-$(notdir $(call strip-suffix,$(file))).css;)
515-
npx postcss --use autoprefixer --use cssnano --no-map --replace public/css/*
516-
@touch $(CSS_DEST)
510+
npx webpack --hide-modules --display-entrypoints=false
511+
@touch $(WEBPACK_DEST)
517512

518513
.PHONY: update-translations
519514
update-translations:

docs/content/doc/advanced/hacking-on-gitea.en-us.md

+7-10
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,20 @@ You should run revive, vet and spell-check on the code with:
140140
make revive vet misspell-check
141141
```
142142

143-
### Working on CSS
143+
### Working on JS and CSS
144144

145-
Edit files in `web_src/less` and run the linter and build the CSS files via:
145+
Edit files in `web_src` and run the linter and build the files in `public`:
146146

147147
```bash
148-
make css
148+
make webpack
149149
```
150150

151-
### Working on JS
151+
Note: When working on frontend code, it is advisable to set `USE_SERVICE_WORKER` to `false` in `app.ini` which will prevent undesirable caching of frontend assets.
152152

153-
Edit files in `web_src/js`, run the linter and build the JS files via:
153+
### Building Images
154154

155-
```bash
156-
make js
157-
```
158-
159-
Note: When working on frontend code, it is advisable to set `USE_SERVICE_WORKER` to `false` in `app.ini` which will prevent undesirable caching of frontend assets.
155+
To build the images, ImageMagick, `inkscape` and `zopflipng` binaries must be available in
156+
your `PATH` to run `make generate-images`.
160157

161158
### Updating the API
162159

0 commit comments

Comments
 (0)