Skip to content

Commit 5094c36

Browse files
docs: migrate to ESM
1 parent f43978e commit 5094c36

76 files changed

Lines changed: 817 additions & 734 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"lint": "run-s lint:*",
4444
"lint:prettier": "prettier --cache --list-different --ignore-unknown .",
4545
"lint:js": "eslint --cache --cache-location .cache/.eslintcache .",
46-
"lint:markdown": "markdownlint --config ./.markdownlint.json '**/*.{md,mdx}'",
46+
"lint:markdown": "markdownlint --config ./.markdownlint.json --rules ./src/utilities/markdown-lint-enforce-lang-aliases.js '**/*.{md,mdx}'",
4747
"lint:prose": "vale --config='.vale.ini' src/content",
4848
"lint:links": "hyperlink -c 8 --root dist -r dist/index.html --canonicalroot https://webpack.js.org/ --internal --skip /plugins/extract-text-webpack-plugin/ --skip /printable --skip /contribute/Governance --skip https:// --skip http:// --skip sw.js --skip /vendor > internal-links.tap; cat internal-links.tap | tap-spot",
4949
"sitemap": "cd dist && sitemap-static --ignore-file=../sitemap-ignore.json --pretty --prefix=https://webpack.js.org/ > sitemap.xml",

src/content/api/cli.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,9 @@ CLI will look for some default configurations in the path of your project, here
404404

405405
This is the lookup priority in increasing order
406406

407-
> example - config file lookup will be in order of .webpack/webpackfile > .webpack/webpack.config.js > webpack.config.js
407+
> example - config file lookup will be in order of webpack.config.js > .webpack/webpack.config.js > .webpack/webpackfile.js
408408
409-
```txt
409+
```text
410410
'webpack.config',
411411
'.webpack/webpack.config',
412412
'.webpack/webpackfile',
@@ -601,7 +601,7 @@ In addition to the customized `env` showed above, there are some built-in ones u
601601

602602
Note that you can not access those built-in environment variables inside the bundled code.
603603

604-
```javascript
604+
```js
605605
export default (env, argv) => ({
606606
mode: env.WEBPACK_SERVE ? "development" : "production",
607607
});
@@ -621,7 +621,7 @@ When the `mode` option is not specified in the configuration, you can use the `-
621621

622622
If your configuration exports a function, the value of `--config-node-env` is assigned to mode after the function returns. This means that `mode` will not be available in the function arguments (`env` and `argv`). However, the value of `--config-node-env` is accessible as `argv.nodeEnv` within the function and can be used accordingly.
623623

624-
```javascript
624+
```js
625625
export default (env, argv) => {
626626
console.log(argv.defineProcessEnvNodeEnv); // 'production' if --config-node-env production is used
627627
return {

src/content/api/hot-module-replacement.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ module.hot.accept("./dep", () => {
186186

187187
A module can self-accept itself, but can invalidate itself when the change is not handleable:
188188

189-
```javascript
189+
```js
190190
const VALUE = "constant";
191191

192192
export default VALUE;
@@ -209,7 +209,7 @@ if (
209209

210210
{/* eslint-disable no-eval */}
211211

212-
```javascript
212+
```js
213213
const moduleId = chooseAModule();
214214
const code = __webpack_modules__[moduleId].toString();
215215
__webpack_modules__[moduleId] = eval(`(${makeChanges(code)})`);

src/content/api/loaders.mdx

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Either `return` or `this.callback` can be used to return the transformed `conten
4747

4848
**sync-loader.js**
4949

50-
```javascript
50+
```js
5151
export default function syncLoader(content, map, meta) {
5252
return someSyncOperation(content);
5353
}
@@ -59,7 +59,7 @@ The `this.callback` method is more flexible as you pass multiple arguments inste
5959

6060
{/* eslint-disable no-useless-return */}
6161

62-
```javascript
62+
```js
6363
export default function syncLoaderWithMultipleResults(content, map, meta) {
6464
this.callback(null, someSyncOperation(content), map, meta);
6565
return; // always return undefined when calling callback()
@@ -72,7 +72,7 @@ For asynchronous loaders, you can return the transformed `content` from an `asyn
7272

7373
**async-loader.js**
7474

75-
```javascript
75+
```js
7676
export default async function asyncLoader(content, map, meta) {
7777
const result = await someAsyncOperation(content);
7878
return result;
@@ -83,7 +83,7 @@ Or you can use [`this.async`](#thisasync) to retrieve the `callback` function:
8383

8484
**async-loader-with-callback.js**
8585

86-
```javascript
86+
```js
8787
export default function asyncLoaderWithCallback(content, map, meta) {
8888
const callback = this.async();
8989
someAsyncOperation(content, (err, result) => {
@@ -95,7 +95,7 @@ export default function asyncLoaderWithCallback(content, map, meta) {
9595

9696
**async-loader-with-multiple-results.js**
9797

98-
```javascript
98+
```js
9999
export default function asyncLoaderWithMultipleResults(content, map, meta) {
100100
const callback = this.async();
101101
someAsyncOperation(content, (err, result, sourceMaps, meta) => {
@@ -113,7 +113,7 @@ By default, the resource file is converted to a UTF-8 string and passed to the l
113113

114114
**raw-loader.js**
115115

116-
```javascript
116+
```js
117117
export default function rawLoader(content) {
118118
assert(content instanceof Buffer);
119119
return someSyncOperation(content);
@@ -131,7 +131,7 @@ T> Loaders may be added inline in requests and disabled via inline prefixes, whi
131131

132132
For the following configuration of [`use`](/configuration/module/#ruleuse):
133133

134-
```javascript
134+
```js
135135
export default {
136136
// ...
137137
module: {
@@ -161,7 +161,7 @@ So why might a loader take advantage of the "pitching" phase?
161161

162162
First, the `data` passed to the `pitch` method is exposed in the execution phase as well under `this.data` and could be useful for capturing and sharing information from earlier in the cycle.
163163

164-
```javascript
164+
```js
165165
export default function myLoaderName(content) {
166166
return someSyncOperation(content, this.data.value);
167167
}
@@ -173,7 +173,7 @@ export function pitch(remainingRequest, precedingRequest, data) {
173173

174174
Second, if a loader delivers a result in the `pitch` method, the process turns around and skips the remaining loaders. In our example above, if the `b-loader`s `pitch` method returned something:
175175

176-
```javascript
176+
```js
177177
export default function myLoaderName(content) {
178178
return someSyncOperation(content);
179179
}
@@ -203,21 +203,21 @@ Given the following example, this require call is used:
203203

204204
In `/abc/file.js`:
205205

206-
```javascript
206+
```js
207207
import "./loader1?xyz!loader2!./resource?rrr";
208208
```
209209

210210
### this.addContextDependency
211211

212-
```typescript
212+
```ts
213213
addContextDependency(directory: string)
214214
```
215215

216216
Add a directory as dependency of the loader result.
217217

218218
### this.addDependency
219219

220-
```typescript
220+
```ts
221221
addDependency(file: string)
222222
dependency(file: string) // shortcut
223223
```
@@ -226,7 +226,7 @@ Add an existing file as a dependency of the loader result in order to make them
226226

227227
### this.addMissingDependency
228228

229-
```typescript
229+
```ts
230230
addMissingDependency(file: string)
231231
```
232232

@@ -240,7 +240,7 @@ Tells the [loader-runner](https://github.com/webpack/loader-runner) that the loa
240240

241241
A function that sets the cacheable flag:
242242

243-
```typescript
243+
```ts
244244
cacheable(flag = true: boolean)
245245
```
246246

@@ -272,7 +272,7 @@ In case this function is called, you should return undefined to avoid ambiguous
272272

273273
### this.clearDependencies
274274

275-
```typescript
275+
```ts
276276
clearDependencies();
277277
```
278278

@@ -290,7 +290,7 @@ A data object shared between the pitch and the normal phase.
290290

291291
### this.emitError
292292

293-
```typescript
293+
```ts
294294
emitError(error: Error)
295295
```
296296

@@ -307,15 +307,15 @@ T> Unlike throwing an Error directly, it will NOT interrupt the compilation proc
307307

308308
### this.emitFile
309309

310-
```typescript
310+
```ts
311311
emitFile(name: string, content: Buffer|string, sourceMap: {...})
312312
```
313313

314314
Emit a file. This is webpack-specific.
315315

316316
### this.emitWarning
317317

318-
```typescript
318+
```ts
319319
emitWarning(warning: Error)
320320
```
321321

@@ -375,7 +375,7 @@ T> Since webpack 5, `this.getOptions` is available in loader context. It substit
375375

376376
### this.getResolve
377377

378-
```typescript
378+
```ts
379379
getResolve(options: ResolveOptions): resolve
380380

381381
resolve(context: string, request: string, callback: function(err, result: string))
@@ -394,7 +394,7 @@ All dependencies of the resolving operation are automatically added as dependenc
394394
395395
Information about HMR for loaders.
396396
397-
```javascript
397+
```js
398398
export default function (source) {
399399
console.log(this.hot); // true if HMR is enabled via --hot flag or webpack configuration
400400
return source;
@@ -466,12 +466,12 @@ export default {
466466
**a-pitching-loader.js**
467467
468468
```js
469-
module.exports.pitch = async function pitch(remaining) {
469+
export async function pitch(remaining) {
470470
const result = await this.importModule(
471471
`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`,
472472
);
473473
return result.default || result;
474-
};
474+
}
475475
```
476476
477477
**src/stylesheet.js**
@@ -512,7 +512,7 @@ In [the example](#example-for-the-loader-context): in loader1: `0`, in loader2:
512512
513513
### this.loadModule
514514
515-
```typescript
515+
```ts
516516
loadModule(request: string, callback: function(err, source, sourceMap, module))
517517
```
518518

@@ -530,7 +530,7 @@ loaders = [{request: string, path: string, query: string, module: function}]
530530

531531
In [the example](#example-for-the-loader-context):
532532

533-
```javascript
533+
```js
534534
[
535535
{
536536
request: "/abc/loader1.js?xyz",
@@ -566,7 +566,7 @@ In [the example](#example-for-the-loader-context): `'/abc/loader1.js?xyz!/abc/no
566566
567567
### this.resolve
568568
569-
```typescript
569+
```ts
570570
resolve(context: string, request: string, callback: function(err, result: string))
571571
```
572572

@@ -701,15 +701,15 @@ For example:
701701
702702
**./src/index.js**
703703
704-
```javascript
704+
```js
705705
import "./loader!./lib";
706706
```
707707
708708
Throwing an error from loader:
709709
710710
**./src/loader.js**
711711
712-
```javascript
712+
```js
713713
export default function (source) {
714714
throw new Error("This is a Fatal Error!");
715715
}
@@ -719,7 +719,7 @@ Or pass an error to the callback in async mode:
719719
720720
**./src/loader.js**
721721
722-
```javascript
722+
```js
723723
export default function (source) {
724724
const callback = this.async();
725725
// ...
@@ -779,7 +779,7 @@ Example:
779779
780780
**file.js**
781781
782-
```javascript
782+
```js
783783
/* STYLE: body { background: red; } */
784784
console.log("yep");
785785
```
@@ -788,7 +788,7 @@ A loader could transform the file into the following file and use the `matchReso
788788
789789
**file.js** (transformed by loader)
790790
791-
```javascript
791+
```js
792792
import "./file.js.css!=!extract-style-loader/getStyles!./file.js";
793793

794794
console.log("yep");
@@ -800,7 +800,7 @@ The loader could look like this:
800800
801801
**extract-style-loader/index.js**
802802
803-
```javascript
803+
```js
804804
import getStylesLoader from "./getStyles";
805805

806806
export default function (source) {
@@ -819,7 +819,7 @@ export default function (source) {
819819
820820
**extract-style-loader/getStyles.js**
821821
822-
```javascript
822+
```js
823823
export default function (source) {
824824
const match = source.match(STYLES_REGEXP);
825825
return match[0];

src/content/api/logging.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Runtime logger API is only intended to be used as a development tool, it is not
8989
- `logging.getLogger('name')`: to get individual logger by name
9090
- `logging.configureDefaultLogger(...)`: to override the default logger.
9191

92-
```javascript
92+
```js
9393
import logging from "webpack/lib/logging/runtime";
9494

9595
logging.configureDefaultLogger({

0 commit comments

Comments
 (0)