Skip to content

Commit 971f71b

Browse files
authored
docs(guides): convert tree shaking webpack.config.js to esm (#7800)
1 parent 35a9ed2 commit 971f71b

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/content/guides/tree-shaking.mdx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ contributors:
1919
- rahul3v
2020
- snitin315
2121
- vansh5632
22+
- Brennvo
2223
related:
2324
- title: Debugging Optimization Bailouts
2425
url: https://webpack.js.org/plugins/module-concatenation-plugin/#debugging-optimization-bailouts
@@ -69,9 +70,13 @@ Set the `mode` configuration option to [development](/configuration/mode/#mode-d
6970
**webpack.config.js**
7071

7172
```diff
72-
const path = require('path');
73+
import path from 'node:path';
74+
import { fileURLToPath } from 'node:url';
7375

74-
module.exports = {
76+
const __filename = fileURLToPath(import.meta.url);
77+
const __dirname = path.dirname(__filename);
78+
79+
export default {
7580
entry: './src/index.js',
7681
output: {
7782
filename: 'bundle.js',
@@ -517,9 +522,13 @@ So we've cued up our "dead code" to be dropped by using the `import` and `export
517522
**webpack.config.js**
518523

519524
```diff
520-
const path = require('path');
525+
import path from 'node:path';
526+
import { fileURLToPath } from 'node:url';
527+
528+
const __filename = fileURLToPath(import.meta.url);
529+
const __dirname = path.dirname(__filename);
521530

522-
module.exports = {
531+
export default {
523532
entry: './src/index.js',
524533
output: {
525534
filename: 'bundle.js',

0 commit comments

Comments
 (0)