Skip to content

Commit ebcf71b

Browse files
committed
docs: update getting started guide to correct webpack config file extension to support CJS syntax
The docs used import statement in index.js which requires setting `type: "module"`. There is a PR for the same `https://github.com/webpack/webpack.js.org/pull/7516`. This is to correct the webpack config file. The commonjs code won't work in *.js extension. So its changed to *.cjs.
1 parent 35023e3 commit ebcf71b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/content/guides/getting-started.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ As of version 4, webpack doesn't require any configuration, but most projects wi
237237
webpack-demo
238238
|- package.json
239239
|- package-lock.json
240-
+ |- webpack.config.js
240+
+ |- webpack.config.cjs
241241
|- /dist
242242
|- index.html
243243
|- /src
244244
|- index.js
245245
```
246246

247-
**webpack.config.js**
247+
**webpack.config.cjs**
248248

249249
```javascript
250250
const path = require('path');
@@ -261,7 +261,7 @@ module.exports = {
261261
Now, let's run the build again but instead using our new configuration file:
262262

263263
```bash
264-
$ npx webpack --config webpack.config.js
264+
$ npx webpack --config webpack.config.cjs
265265
[webpack-cli] Compilation finished
266266
asset main.js 69.3 KiB [compared for emit] [minimized] (name: main) 1 related asset
267267
runtime modules 1000 bytes 5 modules
@@ -271,7 +271,7 @@ cacheable modules 530 KiB
271271
webpack 5.4.0 compiled successfully in 1934 ms
272272
```
273273

274-
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.
274+
T> By default, if you run the webpack command without specifying a configuration file, Webpack will look for certain default filenames. These typically include: `webpack.config.js` (for CommonJS format in JavaScript), `webpack.config.cjs` (for explicit CommonJS format) or `webpack.config.mjs` (for ES Modules). 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.
275275

276276
A configuration file allows far more flexibility than CLI usage. We can specify loader rules, plugins, resolve options and many other enhancements this way. See the [configuration documentation](/configuration) to learn more.
277277

@@ -335,7 +335,7 @@ Now that you have a basic build together you should move on to the next guide [`
335335
webpack-demo
336336
|- package.json
337337
|- package-lock.json
338-
|- webpack.config.js
338+
|- webpack.config.cjs
339339
|- /dist
340340
|- main.js
341341
|- index.html

0 commit comments

Comments
 (0)