You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update documentation examples to ES6 #7636 (#7704)
* docs: Update Getting Started guide to ES Modules syntax
* docs: Update Asset Management guide to ES Modules syntax (fixes#7636)
* successfully update
* Refactor API folder files for ESM compatibility
@@ -649,7 +649,7 @@ When the `mode` option is not specified in the configuration, you can use the `-
649
649
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.
650
650
651
651
```javascript
652
-
module.exports= (env, argv) => {
652
+
exportdefault (env, argv) => {
653
653
console.log(argv.defineProcessEnvNodeEnv); // 'production' if --config-node-env production is used
Or you can use [`this.async`](#thisasync) to retrieve the `callback` function:
81
81
82
82
**async-loader-with-callback.js**
83
83
84
84
```javascript
85
-
module.exports=function (content, map, meta) {
85
+
exportdefaultfunction (content, map, meta) {
86
86
var callback =this.async();
87
87
someAsyncOperation(content, function (err, result) {
88
88
if (err) returncallback(err);
89
89
callback(null, result, map, meta);
90
90
});
91
-
};
91
+
}
92
92
```
93
93
94
94
**async-loader-with-multiple-results.js**
95
95
96
96
```javascript
97
-
module.exports=function (content, map, meta) {
97
+
exportdefaultfunction (content, map, meta) {
98
98
var callback =this.async();
99
99
someAsyncOperation(content, function (err, result, sourceMaps, meta) {
100
100
if (err) returncallback(err);
101
101
callback(null, result, sourceMaps, meta);
102
102
});
103
-
};
103
+
}
104
104
```
105
105
106
106
T> Loaders were originally designed to work in synchronous loader pipelines, like Node.js (using [enhanced-require](https://github.com/webpack/enhanced-require)), _and_ asynchronous pipelines, like in webpack. However, since expensive synchronous computations are a bad idea in a single-threaded environment like Node.js, we advise making your loader asynchronous if possible. Synchronous loaders are ok if the amount of computation is trivial.
@@ -112,13 +112,13 @@ By default, the resource file is converted to a UTF-8 string and passed to the l
112
112
**raw-loader.js**
113
113
114
114
```javascript
115
-
module.exports=function (content) {
115
+
exportdefaultfunction (content) {
116
116
assert(content instanceof Buffer);
117
117
returnsomeSyncOperation(content);
118
118
// return value can be a `Buffer` too
119
119
// This is also allowed if loader is not "raw"
120
-
};
121
-
module.exports.raw=true;
120
+
}
121
+
exportconstraw=true;
122
122
```
123
123
124
124
### Pitching Loader
@@ -130,7 +130,7 @@ T> Loaders may be added inline in requests and disabled via inline prefixes, whi
130
130
For the following configuration of [`use`](/configuration/module/#ruleuse):
131
131
132
132
```javascript
133
-
module.exports= {
133
+
exportdefault {
134
134
//...
135
135
module: {
136
136
rules: [
@@ -160,28 +160,28 @@ So why might a loader take advantage of the "pitching" phase?
160
160
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.
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:
Copy file name to clipboardExpand all lines: src/content/api/logging.mdx
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,12 +50,12 @@ export class MyWebpackPlugin {
50
50
**my-webpack-loader.js**
51
51
52
52
```js
53
-
module.exports=function (source) {
53
+
exportdefaultfunction (source) {
54
54
// you can get Logger with `this.getLogger` in your webpack loaders
55
55
constlogger=this.getLogger('my-webpack-loader');
56
56
logger.info('hello Logger');
57
57
return source;
58
-
};
58
+
}
59
59
```
60
60
61
61
As you can see from the above `my-webpack-plugin.js` example, there're two types of logging methods,
@@ -84,12 +84,12 @@ It's advised to use `compilation.getLogger` when plugin/logging is related to th
84
84
85
85
Runtime logger API is only intended to be used as a development tool, it is not intended to be included in [production mode](/configuration/mode/#mode-production).
86
86
87
-
-`const logging = require('webpack/lib/logging/runtime')`: to use the logger in runtime, require it directly from webpack
87
+
-`import logging from 'webpack/lib/logging/runtime'`: to use the logger in runtime, require it directly from webpack
88
88
-`logging.getLogger('name')`: to get individual logger by name
89
89
-`logging.configureDefaultLogger(...)`: to override the default logger.
0 commit comments