Nested makefile and libraries from CDN

main-old
Antonio De Lucreziis 3 years ago
parent 9aea9bc3a8
commit 9393fa73b9

@ -1,37 +1,31 @@
JS_SOURCES = $(wildcard frontend/src/*.js) GO_SOURCES = $(shell find . -name '*.go')
JS_OUTPUTS = $(patsubst frontend/src/%.js, public/js/%.min.js, $(JS_SOURCES)) GO_EXECUTABLE = phc-website-server
SERVER_EXECUTABLE = phc-website-server
.PHONY: all .PHONY: all
all: js go all: js go
# .PHONY: setup
# Build Frontend setup:
# mkdir -p public/js
.PHONY: js .PHONY: js
js: $(JS_OUTPUTS) js: setup
@echo "Compiled Frontend" $(MAKE) -C frontend/
cp frontend/dist/*.min.js public/js/
public/js/%.min.js: frontend/src/%.js
cd frontend; rollup -c rollup.config.js
mkdir -p public/js
cp $(patsubst frontend/src/%.js, frontend/dist/%.min.js, $<) $@
# #
# Build Server # Build Server
# #
.PHONY: go .PHONY: go
go: $(SERVER_EXECUTABLE) go: $(GO_EXECUTABLE)
@echo "Compiled Server" @echo "Compiled Server"
$(SERVER_EXECUTABLE): $(GO_EXECUTABLE): $(GO_SOURCES)
go build -o $(SERVER_EXECUTABLE) . go build -o $(GO_EXECUTABLE) .
.PHONY: debug .PHONY: debug
debug: debug:
@echo "JS_SOURCES = $(JS_SOURCES)" @echo "GO_SOURCES = $(GO_SOURCES)"
@echo "JS_OUTPUTS = $(JS_OUTPUTS)" @echo "GO_EXECUTABLE = $(GO_EXECUTABLE)"
@echo "SERVER_EXECUTABLE = $(SERVER_EXECUTABLE)"

@ -0,0 +1,14 @@
JS_SOURCES = src/utenti.js
JS_BUNDLES = $(patsubst src/%.js, dist/%.min.js, $(JS_SOURCES))
.PHONY: all
all: $(JS_BUNDLES)
dist/%.min.js: src/%.js
rollup -c rollup.config.js $<
.PHONY: debug
debug:
@echo "JS_SOURCES = $(JS_SOURCES)"
@echo "JS_BUNDLES = $(JS_BUNDLES)"

@ -1,15 +1,24 @@
import { defineConfig } from 'rollup' import { defineConfig } from 'rollup'
import { nodeResolve } from '@rollup/plugin-node-resolve' // import resolve from '@rollup/plugin-node-resolve'
import { terser } from 'rollup-plugin-terser' import { terser } from 'rollup-plugin-terser'
export default defineConfig([ export default defineConfig([
{ {
input: 'src/utenti.js', input: 'src/utenti.js',
external: ['alpinejs', 'fuse.js'], // libraries to not bundle
output: { output: {
file: 'dist/utenti.min.js', file: 'dist/utenti.min.js',
format: 'es', format: 'iife',
globals: {
// map library names to global constants
alpinejs: 'Alpine',
'fuse.js': 'Fuse',
},
}, },
plugins: [terser(), nodeResolve()], plugins: [
// resolve(),
terser(),
],
}, },
]) ])

@ -78,5 +78,3 @@ Alpine.data('utenti', () => ({
console.timeEnd('search') console.timeEnd('search')
}, },
})) }))
Alpine.start()

@ -1,4 +1,9 @@
{{template "base" .}} {{define "title"}}Utenti &bull; PHC{{end}} {{define "body"}} {{template "base" .}}
{{define "title"}}Utenti &bull; PHC{{end}}
{{define "body"}}
<script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js/dist/fuse.js"></script>
<script src="/public/js/utenti.min.js"></script>
<section x-data="utenti"> <section x-data="utenti">
<h2> <h2>
<i class="fas fa-users"></i> <i class="fas fa-users"></i>
@ -51,7 +56,4 @@
</div> </div>
</div> </div>
</section> </section>
<script type="module" src="/public/js/utenti.min.js"></script>
{{end}} {{end}}

Loading…
Cancel
Save