iducationducation
IndexArticlesFormationsProfilOutilsBibliothech
N°014 — 2026
Navigation
01Index02Articles03Formations04Profil05Outils06Bibliothech
N°014 — 2026
iducationducation
IndexArticlesFormationsProfilOutilsBibliothech
N°014 — 2026
Navigation
01Index02Articles03Formations04Profil05Outils06Bibliothech
N°014 — 2026
Formations
TypeScript · Intermédiaire

OpenPatch

Créer et publier une librairie Vue 3 — composant de patch notes avec mode Vue, composable, mode standalone CDN, personnalisation CSS et publication npm.

Vue 3TypeScriptViteTailwind CSS v4
GitHub
01Setup Vite + Vue 3 + TypeScript02Types TypeScript et structure de données03Le composant OpenPatch.vue04Versioning avec localStorage05Le composable useOpenPatch06Mode standalone CDN07Build dual-mode et publication npm
Chapitre 1·15 min

Setup Vite + Vue 3 + TypeScript

On initialise un projet Vite configuré pour produire une librairie Vue 3, pas une application.

Créer le projet

Terminal
npm create vite@latest openpatch -- --template vue-ts
cd openpatch
npm install

Ajouter Tailwind CSS v4

Terminal
npm install tailwindcss @tailwindcss/vite

Tailwind v4 s'intègre comme un plugin Vite — pas de fichier tailwind.config.js.

vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import tailwindcss from '@tailwindcss/vite'
import { resolve } from 'path'
 
export default defineConfig({
  plugins: [vue(), tailwindcss()],
  build: {
    lib: {
      entry: resolve(__dirname, 'src/index.ts'),
      name: 'OpenPatch',
      formats: ['es'],
      fileName: (format) => `index.${format}.js`
    },
    rollupOptions: {
      external: ['vue'],
      output: { globals: { vue: 'Vue' } }
    }
  }
})

external: ['vue'] est crucial — on ne bundle pas Vue dans la librairie. L'application hôte fournit Vue.

Structure cible

src/
├── components/
│   └── OpenPatch.vue       ← composant principal
├── composables/
│   └── useOpenPatch.ts     ← API programmatique
├── types/
│   └── settings.ts         ← types TypeScript
├── utils/
│   └── configLoader.ts     ← chargement config standalone
├── index.ts                ← entry point librairie npm
├── standalone.ts           ← entry point CDN
└── style.css               ← styles Tailwind

Deux entry points : index.ts pour npm, standalone.ts pour le CDN. Le build Vite gère les deux séparément.

Configurer package.json

package.json
{
  "name": "open-patch",
  "version": "1.0.0",
  "main": "./dist/index.es.js",
  "module": "./dist/index.es.js",
  "types": "./dist/index.d.ts",
  "exports": {
    ".": {
      "import": "./dist/index.es.js",
      "types": "./dist/index.d.ts"
    },
    "./style.css": "./dist/open-patch.css"
  },
  "files": ["dist"],
  "peerDependencies": {
    "vue": "^3.0.0"
  }
}

peerDependencies signale à npm que Vue est attendu dans le projet hôte — pas bundlé, pas installé automatiquement.

Suivant
Types TypeScript et structure de données

Développeur fullstack passionné. J'apprends en construisant et je documente tout — front, back, outils. Le code s'apprend mieux en public.

Naviguer

IndexTous les articlesFormationsProfilOutilsBibliothech

Ailleurs

GitHub RSS

Newsletter

Les articles, libs et découvertes. Une fois par semaine, pas plus.

© 2026 William LoreeConçu & codé à la main