Download
Please note that the sample project does not include the Metronic Tailwind CSS source files by default. To integrate the styles, you need to copy the Metronic Tailwind CSS source files from your downloaded Metronic folder.
Copy Source Folder
src
folder from the
metronic-tailwind-html
package and paste it into the Vue
src
directory. Rename the copied folder to
metronic
so that the directory structure should now look like this:
src/metronic
.
This step imports the necessary styles and assets from the original HTML package into your Vue project.
src/metronic/core
folder, delete the unnecessary
index.ts
file. This file is not needed for Single Page Application (SPA) integration as it could cause conflicts. Instead, rename the
index.spa.ts
file to
index.ts
to ensure proper integration.
src/metronic/app/layouts/demo1.js
.
KTLayout
instance initialization from
src/metronic/app/layouts/demo1.js
.
KTDom.ready(() => {
KTLayout.init();
});
Copy Media Folder
media
folder from the
metronic-tailwind-html
package's
dist/assets/media
directory into your Vue project's
public
directory.
Install Packages & Start Development Server
npm
install
. Start the Vue development server by running
npm run dev
.
npm install
npm run dev
Creating Project
Install Node.js and Npm
Before starting with Vue, ensure you have Node.js and npm (Node Package Manager) installed on your machine. Visit https://nodejs.org/ to download and install the latest version.Create an Vue Project
npm create vite@latest metronic-tailwind-vue -- --template vue-ts
cd metronic-tailwind-vue
Install dependencies
npm install @popperjs/core && npm install --D tailwindcss postcss autoprefixer mini-svg-data-uri postcss-import postcss-loader postcss-nesting postcss-preset-env
The command will install the core mandatory dependencies needed to get started with Metronic. If you want to use
apexcharts
,
axios
, or
clipboard
, they must be installed separately.
Serve the Vue Application
npm run dev
http://localhost:5173/
to see your new Vue app in action.
Integrate Styles
Copy Source Folder
src
folder from the
metronic-tailwind-html
package and paste it into the Vue
src
directory. Rename the copied folder to
metronic
so that the directory structure should now look like this:
src/metronic
.
This step imports the necessary styles and assets from the original HTML package into your Vue project.
src/metronic/core
folder, delete the unnecessary
index.ts
file. This file is not needed for Single Page Application (SPA) integration as it could cause conflicts. Instead, rename the
index.spa.ts
file to
index.ts
to ensure proper integration.
src/metronic/app/layouts/demo1.js
.
KTLayout
instance initialization from
src/metronic/app/layouts/demo1.js
.
KTDom.ready(() => {
KTLayout.init();
});
Import Styles
/src/styles.css
and add the following import statement:
@import "./metronic/vendors/keenicons/duotone/style.css";
@import "./metronic/vendors/keenicons/filled/style.css";
@import "./metronic/vendors/keenicons/solid/style.css";
@import "./metronic/vendors/keenicons/outline/style.css";
@import "./metronic/css/styles.css";
#app {
display: contents;
}
Copy Postcss Configuration
postcss.config.js
from
metronic-tailwind-html
and paste it to
metronic-tailwind-vue
.
export default {
plugins: {
'postcss-preset-env': {},
'postcss-import': {},
'tailwindcss/nesting': 'postcss-nesting',
'postcss-preset-env': {
features: { 'nesting-rules': false },
},
'tailwindcss': {},
'autoprefixer': {},
},
}
Copy Tailwind Configuration
tailwind.config.js
file from the
metronic-tailwind-html
package to the root of your
Vue project.
content
and
plugins
array:
// ...
content: ['./index.html', './src/**/*.{js,ts,vue}'],
// ...
// ...
plugins: [
require('./src/metronic/core/plugins/plugin'),
require('./src/metronic/core/plugins/components/theme'),
require('./src/metronic/core/plugins/components/breakpoints'),
require('./src/metronic/core/plugins/components/typography'),
require('./src/metronic/core/plugins/components/menu'),
require('./src/metronic/core/plugins/components/dropdown'),
require('./src/metronic/core/plugins/components/accordion'),
require('./src/metronic/core/plugins/components/input'),
require('./src/metronic/core/plugins/components/input-group'),
require('./src/metronic/core/plugins/components/select'),
require('./src/metronic/core/plugins/components/textarea'),
require('./src/metronic/core/plugins/components/file-input'),
require('./src/metronic/core/plugins/components/switch'),
require('./src/metronic/core/plugins/components/checkbox'),
require('./src/metronic/core/plugins/components/radio'),
require('./src/metronic/core/plugins/components/range'),
require('./src/metronic/core/plugins/components/container'),
require('./src/metronic/core/plugins/components/image-input'),
require('./src/metronic/core/plugins/components/modal'),
require('./src/metronic/core/plugins/components/drawer'),
require('./src/metronic/core/plugins/components/tooltip'),
require('./src/metronic/core/plugins/components/popover'),
require('./src/metronic/core/plugins/components/btn'),
require('./src/metronic/core/plugins/components/btn-group'),
require('./src/metronic/core/plugins/components/tabs'),
require('./src/metronic/core/plugins/components/pagination'),
require('./src/metronic/core/plugins/components/card'),
require('./src/metronic/core/plugins/components/table'),
require('./src/metronic/core/plugins/components/badge'),
require('./src/metronic/core/plugins/components/rating'),
require('./src/metronic/core/plugins/components/scrollable'),
require('./src/metronic/core/plugins/components/progress'),
require('./src/metronic/core/plugins/components/apexcharts'),
require('./src/metronic/core/plugins/components/leaflet')
]
// ...
Setup Static Files
index.html
and media resources in Vue.
Integrate Theme Mode Initialization Script
index.html
content below,
which includes the theme mode initialization script and necessary classes, and paste it into your
metronic-tailwind-vue/index.html
file.
<!doctype html>
<html class="h-full light" data-theme="true" lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue</title>
</head>
<body class="flex h-full demo1 sidebar-fixed header-fixed bg-[#fefefe] dark:bg-coal-500">
<script>
const defaultThemeMode = "light"; // light|dark|system
let themeMode;
if ( document.documentElement ) {
if ( localStorage.getItem("theme")) {
themeMode = localStorage.getItem("theme");
} else if ( document.documentElement.hasAttribute("data-theme-mode")) {
themeMode = document.documentElement.getAttribute("data-theme-mode");
} else {
themeMode = defaultThemeMode;
}
if (themeMode === "system") {
themeMode = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
}
document.documentElement.classList.add(themeMode);
}
</script>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
Copy Media Folder
media
folder from the
metronic-tailwind-html
package's
dist/assets/media
directory into your Vue project's
public
directory.
Integrate Core
Initialize global typescript components
metronic-tailwind-vue/App.vue
add script section with the initialization code in
onMounted
hook.
// App.vue
import { nextTick, onMounted } from 'vue';
import KTComponent from './metronic/core/index.spa';
import KTLayout from './metronic/app/layouts/demo1.js';
onMounted(() => {
nextTick(() => {
KTComponent.init();
KTLayout.init();
});
});
Using typescript initialization with Vue-router
beforeEach
event.
// index.ts
import KTComponent from '../metronic/core/index.spa';
import KTLayout from '../metronic/app/layouts/demo1.js';
router.beforeEach(() => {
KTComponent.init();
KTLayout.init();
});
Disable Strict Mode
tsconfig.json
file, set the
strict
property to
false
.
"strict": false,