Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/content/guides/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,26 @@ As of version 4, webpack doesn't require any configuration, but most projects wi
|- index.js
```

**webpack.config.js**
<CodeGroup>

```javascript
<CodeBlock label="webpack.config.mjs" active>

````javascript
import path from 'path';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
};
</CodeBlock>

<CodeBlock label="webpack.config.cjs">
const path = require('path');

module.exports = {
Expand All @@ -256,7 +273,10 @@ module.exports = {
path: path.resolve(__dirname, 'dist'),
},
};
```
</CodeBlock>

</CodeGroup>


Now, let's run the build again but instead using our new configuration file:

Expand All @@ -269,7 +289,7 @@ cacheable modules 530 KiB
./src/index.js 257 bytes [built] [code generated]
./node_modules/lodash/lodash.js 530 KiB [built] [code generated]
webpack 5.4.0 compiled successfully in 1934 ms
```
````

T> If a `webpack.config.js` is present, the `webpack` command picks it up by default. We use the `--config` option here only to show that you can pass a configuration of any name. This will be useful for more complex configurations that need to be split into multiple files.

Expand Down
Loading