diff --git a/types/webpack-env/index.d.ts b/types/webpack-env/index.d.ts index 6530cfea6e6903..2502e409343d34 100644 --- a/types/webpack-env/index.d.ts +++ b/types/webpack-env/index.d.ts @@ -339,17 +339,35 @@ declare var DEBUG: boolean; interface ImportMeta { /** - * `import.meta.webpackHot` is an alias for` module.hot` which is also available in strict ESM + * `import.meta.url` is the `file:` url of the current file (similar to `__filename` but as file url) */ - webpackHot?: __WebpackModuleApi.Hot | undefined; + url: string; /** * `import.meta.webpack` is the webpack major version as number */ webpack: number; /** - * `import.meta.url` is the `file:` url of the current file (similar to `__filename` but as file url) + * `import.meta.webpackHot` is an alias for` module.hot` which is also available in strict ESM */ - url: string; + webpackHot?: __WebpackModuleApi.Hot | undefined; + /** + * `import.meta.webpackContext` as ESM alternative to `require.context` + * Available: 5.70.0+ + */ + webpackContext?: ( + request: string, + options?: { + recursive?: boolean; + regExp?: RegExp; + include?: RegExp; + exclude?: RegExp; + preload?: boolean | number; + prefetch?: boolean | number; + chunkName?: string; + exports?: string | string[][]; + mode?: 'sync' | 'eager' | 'weak' | 'lazy' | 'lazy-once'; + } + ) => __WebpackModuleApi.RequireContext; } interface NodeModule extends NodeJS.Module {} diff --git a/types/webpack-env/webpack-env-tests.ts b/types/webpack-env/webpack-env-tests.ts index bd95f8505d2b55..85fda642e85c75 100644 --- a/types/webpack-env/webpack-env-tests.ts +++ b/types/webpack-env/webpack-env-tests.ts @@ -148,3 +148,10 @@ if (importMeta.webpack >= 5 && importMeta.webpackHot) { importMeta.webpackHot.addStatusHandler(statusHandler); importMeta.webpackHot.removeStatusHandler(statusHandler); } + +if (importMeta.webpack >= 5 && importMeta.webpackContext) { + let context = importMeta.webpackContext('./somePath', { recursive: true, regExp: /some/, include: /someModule/, exclude: /noNeedModuel/, preload: true, prefetch: true, chunkName: "[request]", exports: "default", mode: "weak" }); + let contextModule = context('./someModule'); + + const contextId: string = importMeta.webpackContext('./somePath').id; +}