static
Le répertoire static
est directement relié à la racine du serveur () et contient des fichiers qui ne seront probablement pas modifiés. Tous les fichiers inclus sont automatiquement servis par Nuxt et accessibles via l'URL racine de votre projet.
/static/robots.txt
sera disponible à l'adresse http://localhost:3000/robots.txt
/static/favicon.ico
sera disponible à l'adresse http://localhost:3000/favicon.ico
Cette option est utile pour les fichiers tels que robots.txt
, sitemap.xml
ou CNAME
(qui est important pour le déploiement des pages sur GitHub).
Ressources statique
Si vous ne souhaitez pas utiliser les ressources Webpack du répertoire assets
, vous pouvez ajouter les images dans le répertoire static
.
Dans votre code, vous pouvez alors référencer ces fichiers par rapport à la racine (/
) :
<!-- Image statique du répertoire `static` -->
<img src="/mon-image.png" />
<!-- Image webpacked du répertoire `assets` -->
<img src="@/assets/mon-image-2.png" />
router.base
vous devrez alors l'ajouter manuellement à vos chemins. Par exemple:<img :src="`${yourPrefix}/my-image.png`" />
Configuration du répertoire static
Si vous en avez besoin, vous pouvez configurer le comportement du répertoire static/
dans le fichier nuxt.config.js
.
Préfixe des ressources statique
Si nous déployons Nuxt dans un sous-répertoire, par exemple /blog/
, la base du routeur sera ajoutée par défaut au chemin de la ressource statique. Si nous voulons désactiver ce comportement, vous pouvez mettre static.prefix
à false
dans le nuxt.config.js
.
export default {
static: {
prefix: false
}
}
Par défaut : /blog/mon-image.png
Avec static.prefix
désactivé : /mon-image.png

























































