Skip to content

Commit b35eb0d

Browse files
authored
docs: fix inconsistent ESM and CommonJS syntax Related to #7772 (#7923)
1 parent 58430ef commit b35eb0d

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

cypress/e2e/code-block-with-copy.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe("CodeBlockWithCopy", () => {
8282

8383
cy.get("@expectedCopiedText").then((expectedCopiedText) => {
8484
expect(copiedText).to.eq(expectedCopiedText);
85-
expect(copiedText).to.include("module.exports = {");
85+
expect(copiedText).to.include("export default {");
8686
expect(copiedText).to.include('entry: "./path/to/my/entry/file.js",');
8787
});
8888
});

src/content/concepts/index.mdx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ By default its value is `./src/index.js`, but you can specify a different (or mu
5454
**webpack.config.js**
5555

5656
```js
57-
module.exports = {
57+
export default {
5858
entry: "./path/to/my/entry/file.js",
5959
};
6060
```
@@ -70,9 +70,13 @@ You can configure this part of the process by specifying an `output` field in yo
7070
**webpack.config.js**
7171

7272
```javascript
73-
const path = require("node:path");
73+
import path from "node:path";
7474

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+
export default {
7680
entry: "./path/to/my/entry/file.js",
7781
output: {
7882
path: path.resolve(__dirname, "dist"),
@@ -99,9 +103,9 @@ At a high level, **loaders** have two properties in your webpack configuration:
99103
**webpack.config.js**
100104
101105
```javascript
102-
const path = require("node:path");
106+
import path from "node:path";
103107

104-
module.exports = {
108+
export default {
105109
output: {
106110
filename: "my-first-webpack.bundle.js",
107111
},
@@ -127,15 +131,15 @@ While loaders are used to transform certain types of modules, plugins can be lev
127131
128132
T> Check out the [plugin interface](/api/plugins) and how to use it to extend webpack's capabilities.
129133
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.
131135
132136
**webpack.config.js**
133137
134138
```javascript
135-
const HtmlWebpackPlugin = require("html-webpack-plugin");
136-
const webpack = require("webpack"); // to access built-in plugins
139+
import HtmlWebpackPlugin from "html-webpack-plugin";
140+
import webpack from "webpack"; // to access built-in plugins
137141

138-
module.exports = {
142+
export default {
139143
module: {
140144
rules: [{ test: /\.txt$/, use: "raw-loader" }],
141145
},
@@ -154,7 +158,7 @@ Using plugins in your webpack configuration is straightforward. However, there a
154158
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`.
155159
156160
```javascript
157-
module.exports = {
161+
export default {
158162
mode: "production",
159163
};
160164
```

0 commit comments

Comments
 (0)