Skip to content

Commit

Permalink
docs: add import.meta.webpackContext (#6029)
Browse files Browse the repository at this point in the history
* docs: add import.meta.webpackContext

* Update src/content/api/module-variables.mdx

Co-authored-by: Nitin Kumar <snitin315@gmail.com>

* update type

* update type

Co-authored-by: Nitin Kumar <snitin315@gmail.com>
  • Loading branch information
ersachin3112 and snitin315 committed Mar 12, 2022
1 parent 0fd0ff3 commit 92fcbb3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/content/api/module-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,40 @@ console.log(import.meta.webpack); // output `5` for webpack 5
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.
## import.meta.webpackContext
Returns the same value as `require.context` but only for `javascript/auto` and `javascript/esm`.
- Type:
```ts
(
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';
}
) => webpack.Context;
```
- Available: 5.70.0+
- Example:
```js
const contextRequire = import.meta.webpackContext('.', {
recursive: false,
regExp: /two/,
mode: 'weak',
exclude: /three/,
});
```
## \_\_filename (NodeJS)
Depending on the configuration option `node.__filename`:
Expand Down

1 comment on commit 92fcbb3

@vercel
Copy link

@vercel vercel bot commented on 92fcbb3 Mar 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.