Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions pages/guides/core-workflows/asset-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ First, make a small change to the project before we begin.

## Loading CSS

To `import` a CSS file from within a JavaScript module, install the [style-loader](/docs/loaders/style-loader) and [css-loader](/docs/loaders/css-loader), then add them to your [`module` configuration](#TODO[/configuration/module]):
To `import` a CSS file from within a JavaScript module, install the [style-loader](/docs/loaders/style-loader) and [css-loader](/docs/loaders/css-loader), then add them to your [`module` configuration](/docs/api/options#module):

```bash
npm install --save-dev style-loader css-loader
Expand Down Expand Up @@ -510,7 +510,7 @@ import { foo } from './data.json';

### Customize parser of JSON modules

You can import `toml`, `yaml`, or `json5` files as JSON modules by supplying a [custom parser](#TODO[/configuration/module/#ruleparserparse]) instead of a dedicated webpack loader.
You can import `toml`, `yaml`, or `json5` files as JSON modules by supplying a [custom parser](/docs/api/options#modulerules) instead of a dedicated webpack loader.

Suppose you have `data.toml`, `data.yaml`, and `data.json5` files in the `src` folder:

Expand Down Expand Up @@ -680,7 +680,7 @@ The best part of everything described above is that loading assets this way lets

This makes your code far more portable, since everything tightly coupled now lives together. If you want to use `/my-component` in another project, just copy or move it into that project's `/components` directory. As long as you've installed any _external dependencies_ and your _configuration defines the same loaders_, it should work.

That said, if you prefer your old habits or you have assets shared across multiple components (views, templates, modules, and so on), you can still keep them in a base directory and use [aliasing](#TODO[/configuration/resolve/#resolvealias]) to make them easier to `import`.
That said, if you prefer your old habits or you have assets shared across multiple components (views, templates, modules, and so on), you can still keep them in a base directory and use [aliasing](/docs/api/options#resolvealias) to make them easier to `import`.

## Wrapping up

Expand Down
14 changes: 7 additions & 7 deletions pages/guides/core-workflows/asset-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ import mainImage from './images/main.png';
img.src = mainImage; // '/dist/151cfcfa1bd74779aadb.png'
```

All `.png` files will be emitted to the output directory and their paths will be injected into the bundles. You can also customize [`outputPath`](#TODO[/configuration/module/#rulegeneratoroutputpath]) and [`publicPath`](#TODO[/configuration/module/#rulegeneratorpublicpath]) for them.
All `.png` files will be emitted to the output directory and their paths will be injected into the bundles. You can also customize [`outputPath`](/docs/api/options#modulerules) and [`publicPath`](/docs/api/options#modulerules) for them.

### Custom output filename

By default, `asset/resource` modules are emitted into the output directory using the `[hash][ext][query]` filename template.

You can change this template by setting [`output.assetModuleFilename`](#TODO[/configuration/output/#outputassetmodulefilename]) in your webpack configuration:
You can change this template by setting [`output.assetModuleFilename`](/docs/api/options#outputassetmodulefilename) in your webpack configuration:

```diff displayName="webpack.config.js"
import path from "node:path";
Expand Down Expand Up @@ -189,7 +189,7 @@ export default {

With this configuration, all `.html` files will be emitted into a `static` directory inside the output directory.

`Rule.generator.filename` behaves the same as [`output.assetModuleFilename`](#TODO[/configuration/output/#outputassetmodulefilename]) and works only with the `asset` and `asset/resource` module types.
`Rule.generator.filename` behaves the same as [`output.assetModuleFilename`](/docs/api/options#outputassetmodulefilename) and works only with the `asset` and `asset/resource` module types.

## Inlining assets

Expand Down Expand Up @@ -325,7 +325,7 @@ When you use `new URL('./path/to/asset', import.meta.url)`, webpack creates an a
const logo = new URL('./logo.svg', import.meta.url);
```

Depending on the [`target`](#TODO[/configuration/target/]) in your configuration, webpack compiles the code above into different output:
Depending on the [`target`](/docs/api/options#target) in your configuration, webpack compiles the code above into different output:

```js
// target: web
Expand Down Expand Up @@ -386,7 +386,7 @@ export default {

Now webpack automatically chooses between `resource` and `inline` based on a default condition: a file smaller than 8kb is treated as an `inline` module type, and larger files use the `resource` module type.

You can change this condition by setting the [`Rule.parser.dataUrlCondition.maxSize`](#TODO[/configuration/module/#ruleparserdataurlcondition]) option at the module rule level of your webpack configuration:
You can change this condition by setting the [`Rule.parser.dataUrlCondition.maxSize`](/docs/api/options#modulerules) option at the module rule level of your webpack configuration:

```diff displayName="webpack.config.js"
import path from "node:path";
Expand Down Expand Up @@ -417,7 +417,7 @@ export default {
};
```

You can also [specify a function](#TODO[/configuration/module/#ruleparserdataurlcondition]) to decide whether to inline a module.
You can also [specify a function](/docs/api/options#modulerules) to decide whether to inline a module.

## Bytes type

Expand Down Expand Up @@ -542,7 +542,7 @@ module: {

## Disable emitting assets

For use cases such as server-side rendering, you might want to disable emitting assets. This is possible with the [`emit`](#TODO[/configuration/module/#rulegeneratoremit]) option under `Rule.generator`:
For use cases such as server-side rendering, you might want to disable emitting assets. This is possible with the [`emit`](/docs/api/options#modulerules) option under `Rule.generator`:

```js
export default {
Expand Down
12 changes: 6 additions & 6 deletions pages/guides/core-workflows/development/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If you've worked through the previous guides, you should now have a solid grasp
> [!WARNING]
> The tools described in this guide are intended **only for development**. Do **not** use them in production.

Start by setting [`mode` to `'development'`](#TODO[/configuration/mode/#mode-development]) and `title` to `'Development'`.
Start by setting [`mode` to `'development'`](/docs/api/options#mode) and `title` to `'Development'`.

```diff displayName="webpack.config.js"
import path from 'node:path';
Expand Down Expand Up @@ -48,7 +48,7 @@ When webpack bundles your source code, tracing errors and warnings back to their

To make errors and warnings easier to track down, JavaScript supports [source maps](http://blog.teamtreehouse.com/introduction-source-maps), which map your compiled code back to the original source. If an error originates in `b.js`, the source map will tell you precisely that.

webpack offers many [different options](#TODO[/configuration/devtool]) for source maps. It's worth reviewing them so you can pick the one that fits your needs.
webpack offers many [different options](/docs/api/options#devtool) for source maps. It's worth reviewing them so you can pick the one that fits your needs.

For this guide, we'll use the `inline-source-map` option. It's well suited for demonstration, though not for production:

Expand Down Expand Up @@ -123,7 +123,7 @@ Manually running `npm run build` every time you want to compile quickly becomes

webpack provides several options that recompile your code automatically whenever it changes:

1. webpack's [Watch Mode](#TODO[/configuration/watch/#watch])
1. webpack's [Watch Mode](/docs/api/options#watch)
2. [webpack-dev-server](https://github.com/webpack/webpack-dev-server)
3. [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware)

Expand Down Expand Up @@ -225,10 +225,10 @@ This tells `webpack-dev-server` to serve the files from the `dist` directory on
> `optimization.runtimeChunk: 'single'` was added because this example uses more than one entry point on a single HTML page. Without it, we'd run into the problem described [here](https://bundlers.tooling.report/code-splitting/multi-entry/). See the [Code Splitting](/guides/optimization/code-splitting) chapter for more details.

> [!TIP]
> `webpack-dev-server` serves bundled files from the directory defined in [`output.path`](#TODO[/configuration/output/#outputpath]); that is, files are available under `http://[devServer.host]:[devServer.port]/[output.publicPath]/[output.filename]`.
> `webpack-dev-server` serves bundled files from the directory defined in [`output.path`](/docs/api/options#outputpath); that is, files are available under `http://[devServer.host]:[devServer.port]/[output.publicPath]/[output.filename]`.

> [!WARNING]
> `webpack-dev-server` doesn't write any output files after compiling. Instead, it keeps the bundles in memory and serves them as if they were real files mounted at the server's root path. If your page expects the bundles at a different path, change it with the [`devMiddleware.publicPath`](#TODO[/configuration/dev-server/#devserverdevmiddleware]) option in the dev server's configuration.
> `webpack-dev-server` doesn't write any output files after compiling. Instead, it keeps the bundles in memory and serves them as if they were real files mounted at the server's root path. If your page expects the bundles at a different path, change it with the [`devMiddleware.publicPath`](/docs/api/options#devserver) option in the dev server's configuration.

Let's also add a script to make running the dev server easier:

Expand Down Expand Up @@ -261,7 +261,7 @@ Let's also add a script to make running the dev server easier:

Now run `npm start` from the command line, and your browser will open the page automatically. Change and save any source file, and the server will reload once the code has recompiled. Give it a try!

`webpack-dev-server` offers many configurable options. Head over to the [documentation](#TODO[/configuration/dev-server]) to learn more.
`webpack-dev-server` offers many configurable options. Head over to the [documentation](/docs/api/options#devserver) to learn more.

> [!TIP]
> Now that your server is up and running, you might want to give [Hot Module Replacement](/guides/core-workflows/development/hot-module-replacement) a try!
Expand Down
6 changes: 3 additions & 3 deletions pages/guides/core-workflows/output-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ webpack 5.x.x compiled successfully in 1996 ms

webpack generates `print.bundle.js` and `index.bundle.js`, both of which we referenced in `index.html`. Open `index.html` in your browser and click the button to see what happens.

But what if we renamed one of our entry points, or added a new one? The generated bundles would be renamed on the next build, yet `index.html` would still reference the old names. Let's fix that with [`HtmlWebpackPlugin`](#TODO[/plugins/html-webpack-plugin]).
But what if we renamed one of our entry points, or added a new one? The generated bundles would be renamed on the next build, yet `index.html` would still reference the old names. Let's fix that with [`HtmlWebpackPlugin`](https://www.npmjs.com/package/html-webpack-plugin).

> [!TIP]
> If you inspected `print.bundle.js`, you might have noticed that it does not contain the `printMe` function. Instead, it contains only an [IIFE](/guides/getting-started/concepts/why-webpack/#iifes---immediately-invoked-function-expressions) with no observable side effects.
Expand Down Expand Up @@ -182,7 +182,7 @@ To learn more about the features and options that `HtmlWebpackPlugin` provides,

As you may have noticed over the previous guides and examples, our `/dist` folder has become cluttered. webpack generates files and places them in `/dist` for you, but it doesn't track which files are actually still in use.

In general, it's good practice to clean the `/dist` folder before each build so that only the files in use are generated. The [`output.clean`](#TODO[/configuration/output/#outputclean]) option takes care of this:
In general, it's good practice to clean the `/dist` folder before each build so that only the files in use are generated. The [`output.clean`](/docs/api/options#outputclean) option takes care of this:

```diff displayName="webpack.config.js"
import path from 'node:path';
Expand Down Expand Up @@ -214,7 +214,7 @@ Run `npm run build` again and inspect the `/dist` folder. If everything went wel

## The manifest

You might wonder how webpack and its plugins seem to "know" which files are being generated. The answer lies in the manifest that webpack keeps to track how all the modules map to the output bundles. If you're interested in managing webpack's [`output`](#TODO[/configuration/output]) in other ways, the manifest is a good place to start.
You might wonder how webpack and its plugins seem to "know" which files are being generated. The answer lies in the manifest that webpack keeps to track how all the modules map to the output bundles. If you're interested in managing webpack's [`output`](/docs/api/options#output) in other ways, the manifest is a good place to start.

The manifest data can be extracted into a JSON file for consumption using the [`ManifestPlugin`](/docs/api/plugins/ManifestPlugin).

Expand Down
10 changes: 5 additions & 5 deletions pages/guides/core-workflows/production.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Feel free to run these scripts and watch how the output changes as we continue b

## Specify the mode

Many libraries key off the `process.env.NODE_ENV` variable to decide what to include. For example, when `process.env.NODE_ENV` is not set to `'production'`, some libraries add extra logging and testing to ease debugging; when it is set to `'production'`, they may drop or add significant portions of code to optimize for your real users. Since webpack v4, specifying [`mode`](#TODO[/configuration/mode/]) automatically configures `process.env.NODE_ENV` for you via [`DefinePlugin`](https://github.com/webpack/webpack/blob/fcccd192ce550210186f84a7ca59ee4cd47a8b2d/lib/WebpackOptionsApply.js#L565):
Many libraries key off the `process.env.NODE_ENV` variable to decide what to include. For example, when `process.env.NODE_ENV` is not set to `'production'`, some libraries add extra logging and testing to ease debugging; when it is set to `'production'`, they may drop or add significant portions of code to optimize for your real users. Since webpack v4, specifying [`mode`](/docs/api/options#mode) automatically configures `process.env.NODE_ENV` for you via [`DefinePlugin`](https://github.com/webpack/webpack/blob/fcccd192ce550210186f84a7ca59ee4cd47a8b2d/lib/WebpackOptionsApply.js#L565):

```diff displayName="webpack.prod.js"
import { merge } from 'webpack-merge';
Expand Down Expand Up @@ -165,17 +165,17 @@ If you use a library like [`react`](https://reactjs.org/), you should see a sign

## Minification

webpack v4+ minifies your code by default in [production mode](#TODO[/configuration/mode/#mode-production]).
webpack v4+ minifies your code by default in [production mode](/docs/api/options#mode).

While the [`MinimizerPlugin`](/docs/plugins/minimizer-webpack-plugin) is a great starting point and is used by default, other options exist:

- [`ClosureWebpackPlugin`](https://github.com/webpack-contrib/closure-webpack-plugin)

If you decide to try another minification plugin, make sure your choice also drops dead code as described in the [tree shaking](/guides/optimization/tree-shaking) guide, and provide it via [`optimization.minimizer`](#TODO[/configuration/optimization/#optimizationminimizer]).
If you decide to try another minification plugin, make sure your choice also drops dead code as described in the [tree shaking](/guides/optimization/tree-shaking) guide, and provide it via [`optimization.minimizer`](/docs/api/options#optimizationminimizer).

## Source mapping

We encourage you to enable source maps in production, as they're useful for debugging as well as for running benchmark tests. That said, choose one with a reasonably quick build speed that's recommended for production use (see [`devtool`](#TODO[/configuration/devtool])). For this guide, we'll use the `source-map` option in production, as opposed to the `inline-source-map` we used in development:
We encourage you to enable source maps in production, as they're useful for debugging as well as for running benchmark tests. That said, choose one with a reasonably quick build speed that's recommended for production use (see [`devtool`](/docs/api/options#devtool)). For this guide, we'll use the `source-map` option in production, as opposed to the `inline-source-map` we used in development:

```diff displayName="webpack.prod.js"
import { merge } from 'webpack-merge';
Expand All @@ -196,6 +196,6 @@ It's crucial to minimize your CSS for production. See the [Minimizing for Produc

## CLI alternatives

Many of the options described above can be set as command-line arguments. For example, [`optimization.minimize`](#TODO[/configuration/optimization/#optimizationminimize]) can be set with `--optimization-minimize`, and [`mode`](#TODO[/configuration/mode/]) can be set with `--mode`. Run `npx webpack --help=verbose` for a full list of CLI arguments.
Many of the options described above can be set as command-line arguments. For example, [`optimization.minimize`](/docs/api/options#optimizationminimize) can be set with `--optimization-minimize`, and [`mode`](/docs/api/options#mode) can be set with `--mode`. Run `npx webpack --help=verbose` for a full list of CLI arguments.

While these shorthand methods are useful, we recommend setting these options in a webpack configuration file for greater configurability.
10 changes: 3 additions & 7 deletions pages/guides/getting-started/concepts/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors: TheLarkInn,simon04,EugeneHlushko,byzyk,mr-baraiya,avivkeller

# Configuration

You may have noticed that very few webpack configurations look exactly alike. That's because a webpack configuration file is simply a JavaScript file that exports a webpack [configuration](#TODO[/configuration/]). webpack then processes that configuration according to the properties you define on it.
You may have noticed that very few webpack configurations look exactly alike. That's because a webpack configuration file is simply a JavaScript file that exports a webpack [configuration](/docs/api/options). webpack then processes that configuration according to the properties you define on it.

Since the configuration is a standard Node.js module, you can do all of the following:

Expand Down Expand Up @@ -46,7 +46,7 @@ export default {
};
```

See the [Configuration section](#TODO[/configuration/]) for every supported configuration option.
See the [Configuration section](/docs/api/options) for every supported configuration option.

## Using multiple configurations

Expand All @@ -73,12 +73,8 @@ module.exports = [

## Multiple targets

In addition to exporting a single configuration as an object, a [function](#TODO[/configuration/configuration-types/#exporting-a-function]), or a [Promise](#TODO[/configuration/configuration-types/#exporting-a-promise]), you can export multiple configurations.

See [Exporting multiple configurations](#TODO[/configuration/configuration-types/#exporting-multiple-configurations]).
In addition to exporting a single configuration as an object, a [function](/guides/core-workflows/environment-variables), or a Promise, you can export multiple configurations.

## Using other configuration languages

webpack accepts configuration files written in several programming and data languages.

See [Configuration Languages](#TODO[/configuration/configuration-languages/]).
Loading
Loading