Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor(DevOps): Inicial automatizar o build do front end integrado com o back end #132

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions API/AcheiUnB/static/dist/.vite/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"index.html": {
"file": "js/index-Dmqp8QMV.js",
"name": "index",
"src": "index.html",
"isEntry": true,
"css": [
"assets/index-DZIDT3qk.css"
],
"assets": [
"assets/carteira-Dk-44drH.png",
"assets/bone-DE10Yqga.png",
"assets/caneta-CQ7HO7XX.png",
"assets/gloss-CzT_QGW8.png",
"assets/sombrinha-B7Nq8G48.png",
"assets/Favicon-DZaE_dAz.png"
]
},
"src/assets/icons/Favicon.png": {
"file": "assets/Favicon-DZaE_dAz.png",
"src": "src/assets/icons/Favicon.png"
},
"src/assets/images/bone.png": {
"file": "assets/bone-DE10Yqga.png",
"src": "src/assets/images/bone.png"
},
"src/assets/images/caneta.png": {
"file": "assets/caneta-CQ7HO7XX.png",
"src": "src/assets/images/caneta.png"
},
"src/assets/images/carteira.png": {
"file": "assets/carteira-Dk-44drH.png",
"src": "src/assets/images/carteira.png"
},
"src/assets/images/gloss.png": {
"file": "assets/gloss-CzT_QGW8.png",
"src": "src/assets/images/gloss.png"
},
"src/assets/images/sombrinha.png": {
"file": "assets/sombrinha-B7Nq8G48.png",
"src": "src/assets/images/sombrinha.png"
}
}

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions API/AcheiUnB/static/dist/index.html

This file was deleted.

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions API/users/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
{% load static %}
{% load vite_tags %}

<!DOCTYPE html>
<html lang="pt-br">

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/static/dist/assets/Favicon-DZaE_dAz.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="UTF-8"/>
<link rel="icon" type="image/png" href="{% static 'dist/assets/Favicon-DZaE_dAz.png' %}"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>AcheiUnB</title>
<link rel="stylesheet" href="{% static '/assets/index-BPbdc-EE.css' %}" />
</head>
<!-- Carrega automaticamente o CSS certo -->
<link rel="stylesheet" href="{% vite_asset 'index.html' 'css' %}"/>
<!-- Observe acima que pegamos o 'src/main.js' do manifest,
mas na verdade, se o manifest listar CSS separado, pode estar em outro lugar.
Leia o JSON para saber as chaves exatas. -->

</head>
<body>
<div id="app"></div>
<script src="{% static '/js/index-D1-PH3MR.js' %}"></script>
<!-- Carrega automaticamente o JS certo -->
<script src="{% vite_asset 'index.html' 'js' %}"></script>
</body>

</html>
</html>
40 changes: 40 additions & 0 deletions API/users/templatetags/vite_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import json
import os

from django import template
from django.conf import settings

register = template.Library()

# Ler o manifest ao carregar o arquivo (você pode melhorar, cachear, etc.)
MANIFEST_PATH = os.path.join(
settings.BASE_DIR, "AcheiUnB", "static", "dist", ".vite", "manifest.json"
)
with open(MANIFEST_PATH, "r") as f:
manifest = json.load(f)


@register.simple_tag
@register.simple_tag
def vite_asset(entry_name="index.html", asset_type="js"):
"""
Retorna o caminho principal de JS ou de CSS.
Exemplo:
{% vite_asset 'index.html' 'js' %}
{% vite_asset 'index.html' 'css' %}
"""
if entry_name not in manifest:
return ""
entry_data = manifest[entry_name]

if asset_type == "js":
# 'file' = js principal
return f"/static/dist/{entry_data.get('file', '')}"
elif asset_type == "css":
css_files = entry_data.get("css", [])
if css_files:
return f"/static/dist/{css_files[0]}"
else:
return ""
else:
return ""
1 change: 1 addition & 0 deletions web/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default defineConfig({
base: "static/dist/",
build: {
outDir: path.resolve(__dirname, "../API/AcheiUnB/static/dist"),
manifest: true,
emptyOutDir: true,
assetsDir: "static/dist/assets", // Pasta onde as imagens e outros arquivos estáticos serão armazenados

Expand Down
Loading