Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: updated getting started guide to correct webpack config file extension to support CJS syntax #7518

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
11 changes: 6 additions & 5 deletions src/content/guides/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ contributors:
- d3lm
- snitin315
- Etheryen
- RajeevPullat
---

Webpack is used to compile JavaScript modules. Once [installed](/guides/installation), you can interact with webpack either from its [CLI](/api/cli) or [API](/api/node). If you're still new to webpack, please read through the [core concepts](/concepts) and [this comparison](/comparison) to learn why you might use it over the other tools that are out in the community.
Expand Down Expand Up @@ -237,14 +238,14 @@ As of version 4, webpack doesn't require any configuration, but most projects wi
webpack-demo
|- package.json
|- package-lock.json
+ |- webpack.config.js
+ |- webpack.config.cjs
|- /dist
|- index.html
|- /src
|- index.js
```

**webpack.config.js**
**webpack.config.cjs**

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

```bash
$ npx webpack --config webpack.config.js
$ npx webpack --config webpack.config.cjs
[webpack-cli] Compilation finished
asset main.js 69.3 KiB [compared for emit] [minimized] (name: main) 1 related asset
runtime modules 1000 bytes 5 modules
Expand All @@ -271,7 +272,7 @@ cacheable modules 530 KiB
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.
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.

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.

Expand Down Expand Up @@ -335,7 +336,7 @@ Now that you have a basic build together you should move on to the next guide [`
webpack-demo
|- package.json
|- package-lock.json
|- webpack.config.js
|- webpack.config.cjs
|- /dist
|- main.js
|- index.html
Expand Down
Loading