import.meta
Syntax
Value
There’s two distinct import.meta
objects: The object that is referenced in source files
and the object that exists when running the application. Since the value is specific to
individual files, references to import.meta
are typically replaced during bundling.
For authoring code, bundlers may provide the following properties:
url
- A reference to the current module that can be used to reference other resources. Often used in combination with the
URL
constructor. resolve
- Resolves a given specifier in the context of the current file. Very similar to
url
but more concise for common use cases. hot
Experimental- During development, this may be an object that provides APIs for handling hot replacement. The details of the API are bundler specific.
env
Experimental- Object that contains custom environment settings, e.g. those read from
.env
files. env.DEV
andenv.PROD
Experimentalenv.DEV
is a boolean that specifies if development-time debug assertions should be enabled, e.g. because the code is running in an interactive development environment. It’s opposite isenv.PROD
which should always be equal to!env.DEV
.env.MODE
Experimental- A string description for a “bundling mode”. May include any user-defined string.
env.SSR
Experimental- A boolean that is true if the code is running as part of SSR (server-side rendering).
webpack
,webpackHot
, andwebpackContext
Experimental- The major version of webpack used to bundle, webpack’s hot module replacement API for this module, and contextual information about how this module was included in the current webpack build.
Specifications
Bundler compatibility
Bundlers | Runtimes | |||||||
---|---|---|---|---|---|---|---|---|
esbuild | Rsbuild | Rspack | Vite | Webpack | Bun | Deno | Node.js | |
import.meta | ||||||||
import.meta.url | ||||||||
Worker from import.meta.url | ||||||||
import.meta.resolve | ||||||||
import.meta.env Experimental | ||||||||
import.meta.env?.X Experimental | ||||||||
import.meta.hot Experimental | ||||||||
import.meta.webpack* Experimental |