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
Copy file name to clipboardExpand all lines: src/content/concepts/index.mdx
+14-10Lines changed: 14 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,7 @@ By default its value is `./src/index.js`, but you can specify a different (or mu
54
54
**webpack.config.js**
55
55
56
56
```js
57
-
module.exports= {
57
+
exportdefault {
58
58
entry:"./path/to/my/entry/file.js",
59
59
};
60
60
```
@@ -70,9 +70,13 @@ You can configure this part of the process by specifying an `output` field in yo
70
70
**webpack.config.js**
71
71
72
72
```javascript
73
-
constpath=require("node:path");
73
+
importpathfrom"node:path";
74
74
75
-
module.exports= {
75
+
// For compatibility with older Node.js versions
76
+
const__filename=fileURLToPath(import.meta.url);
77
+
const__dirname=path.dirname(__filename);
78
+
79
+
exportdefault {
76
80
entry:"./path/to/my/entry/file.js",
77
81
output: {
78
82
path:path.resolve(__dirname, "dist"),
@@ -99,9 +103,9 @@ At a high level, **loaders** have two properties in your webpack configuration:
99
103
**webpack.config.js**
100
104
101
105
```javascript
102
-
constpath=require("node:path");
106
+
importpathfrom"node:path";
103
107
104
-
module.exports= {
108
+
exportdefault {
105
109
output: {
106
110
filename:"my-first-webpack.bundle.js",
107
111
},
@@ -127,15 +131,15 @@ While loaders are used to transform certain types of modules, plugins can be lev
127
131
128
132
T> Check out the [plugin interface](/api/plugins) and how to use it to extend webpack's capabilities.
129
133
130
-
In order to use a plugin, you need to `require()` it and add it to the `plugins` array. Most plugins are customizable through options. Since you can use a plugin multiple times in a configuration for different purposes, you need to create an instance of it by calling it with the `new` operator.
134
+
In order to use a plugin, you need to `import` it and add it to the `plugins` array. Most plugins are customizable through options. Since you can use a plugin multiple times in a configuration for different purposes, you need to create an instance of it by calling it with the `new` operator.
constwebpack=require("webpack"); // to access built-in plugins
139
+
importHtmlWebpackPluginfrom"html-webpack-plugin";
140
+
importwebpackfrom"webpack"; // to access built-in plugins
137
141
138
-
module.exports= {
142
+
exportdefault {
139
143
module: {
140
144
rules: [{ test:/\.txt$/, use:"raw-loader" }],
141
145
},
@@ -154,7 +158,7 @@ Using plugins in your webpack configuration is straightforward. However, there a
154
158
By setting the `mode` parameter to either `development`, `production` or `none`, you can enable webpack's built-in optimizations that correspond to each environment. The default value is `production`.
0 commit comments