Skip to content

Commit 92fcbb3

Browse files
docs: add import.meta.webpackContext (#6029)
* docs: add import.meta.webpackContext * Update src/content/api/module-variables.mdx Co-authored-by: Nitin Kumar <[email protected]> * update type * update type Co-authored-by: Nitin Kumar <[email protected]>
1 parent 0fd0ff3 commit 92fcbb3

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/content/api/module-variables.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,40 @@ console.log(import.meta.webpack); // output `5` for webpack 5
105105
106106
Webpack specific. An alias for [`module.hot`](#modulehot-webpack-specific), however `import.meta.webpackHot` can be used in [strict ESM](/guides/ecma-script-modules/#flagging-modules-as-esm) while `module.hot` can't.
107107
108+
## import.meta.webpackContext
109+
110+
Returns the same value as `require.context` but only for `javascript/auto` and `javascript/esm`.
111+
112+
- Type:
113+
114+
```ts
115+
(
116+
request: string,
117+
options?: {
118+
recursive?: boolean;
119+
regExp?: RegExp;
120+
include?: RegExp;
121+
exclude?: RegExp;
122+
preload?: boolean | number;
123+
prefetch?: boolean | number;
124+
chunkName?: string;
125+
exports?: string | string[][];
126+
mode?: 'sync' | 'eager' | 'weak' | 'lazy' | 'lazy-once';
127+
}
128+
) => webpack.Context;
129+
```
130+
131+
- Available: 5.70.0+
132+
- Example:
133+
```js
134+
const contextRequire = import.meta.webpackContext('.', {
135+
recursive: false,
136+
regExp: /two/,
137+
mode: 'weak',
138+
exclude: /three/,
139+
});
140+
```
141+
108142
## \_\_filename (NodeJS)
109143
110144
Depending on the configuration option `node.__filename`:

0 commit comments

Comments
 (0)