Peter Mekhaeil

import.meta

import.meta is an object that is available within Javascript ES modules. It contains metadata about the module and is extensible.

It contains import.meta.url that returns the full URL of the module.

<script type="module" src="module.mjs"></script>
// module.mjs
let img = document.createElement('img');
img.src = new URL('image.jpg', import.meta.url);
document.body.appendChild(img);

Difference from process.env

process.env is specific to Node and cannot be used in the browser.

TypeScript support

interface ImportMeta {
  myVariable: string
}

import.meta.myVariable; // string

Uses

Vite extend import.meta to add things like: