Skip to content

Commit f8a6944

Browse files
authored
docs(guides): some fixes (#4172)
1 parent 4646848 commit f8a6944

File tree

4 files changed

+64
-73
lines changed

4 files changed

+64
-73
lines changed

src/content/guides/asset-management.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ If you've been following the guides from the start, you will now have a small pr
1717

1818
Prior to webpack, front-end developers would use tools like [grunt](https://gruntjs.com/) and [gulp](https://gulpjs.com/) to process these assets and move them from their `/src` folder into their `/dist` or `/build` directory. The same idea was used for JavaScript modules, but tools like webpack will __dynamically bundle__ all dependencies (creating what's known as a [dependency graph](/concepts/dependency-graph)). This is great because every module now _explicitly states its dependencies_ and we'll avoid bundling modules that aren't in use.
1919

20-
One of the coolest webpack features is that you can also _include any other type of file_, besides JavaScript, for which there is a loader. This means that the same benefits listed above for JavaScript (e.g. explicit dependencies) can be applied to everything used in building a website or web app. Let's start with CSS, as you may already be familiar with that setup.
20+
One of the coolest webpack features is that you can also _include any other type of file_, besides JavaScript, for which there is a loader or built-in [Asset Modules](/guides/asset-modules/) support. This means that the same benefits listed above for JavaScript (e.g. explicit dependencies) can be applied to everything used in building a website or web app. Let's start with CSS, as you may already be familiar with that setup.
2121

2222
## Setup
2323

@@ -145,18 +145,18 @@ $ npm run build
145145

146146
...
147147
[webpack-cli] Compilation finished
148-
asset bundle.js 72.6 KiB [compared for emit] [minimized] (name: main) 1 related asset
148+
asset bundle.js 72.6 KiB [emitted] [minimized] (name: main) 1 related asset
149149
runtime modules 1000 bytes 5 modules
150150
orphan modules 326 bytes [orphan] 1 module
151151
cacheable modules 539 KiB
152152
modules by path ./node_modules/ 538 KiB
153153
./node_modules/lodash/lodash.js 530 KiB [built] [code generated]
154154
./node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js 6.67 KiB [built] [code generated]
155155
./node_modules/css-loader/dist/runtime/api.js 1.57 KiB [built] [code generated]
156-
modules by path ./src/ 966 bytes
157-
./src/index.js + 1 modules 640 bytes [built] [code generated]
156+
modules by path ./src/ 965 bytes
157+
./src/index.js + 1 modules 639 bytes [built] [code generated]
158158
./node_modules/css-loader/dist/cjs.js!./src/style.css 326 bytes [built] [code generated]
159-
webpack 5.4.0 compiled successfully in 2900 ms
159+
webpack 5.4.0 compiled successfully in 2231 ms
160160
```
161161

162162
Open up `dist/index.html` in your browser again and you should see that `Hello webpack` is now styled in red. To see what webpack did, inspect the page (don't view the page source, as it won't show you the result, because the `<style>` tag is dynamically created by JavaScript) and look at the page's head tags. It should contain the style block that we imported in `index.js`.
@@ -166,7 +166,7 @@ Note that you can, and in most cases should, [minimize css](/plugins/mini-css-ex
166166

167167
## Loading Images
168168

169-
So now we're pulling in our CSS, but what about our images like backgrounds and icons? As of webpack 5, using the [Asset Modules](/guides/asset-modules/) we can easily incorporate those in our system as well:
169+
So now we're pulling in our CSS, but what about our images like backgrounds and icons? As of webpack 5, using the built-in [Asset Modules](/guides/asset-modules/) we can easily incorporate those in our system as well:
170170

171171
__webpack.config.js__
172172

@@ -249,32 +249,32 @@ __src/style.css__
249249
}
250250
```
251251

252-
Let's create a new build and open up the index.html file again:
252+
Let's create a new build and open up the `index.html` file again:
253253

254254
``` bash
255255
$ npm run build
256256

257257
...
258258
[webpack-cli] Compilation finished
259-
asset 3b7bf087cbac835e6f7d.png 233 KiB [emitted] [immutable] [from: src/icon.png] (auxiliary name: main)
259+
assets by status 9.88 KiB [cached] 1 asset
260260
asset bundle.js 73.4 KiB [emitted] [minimized] (name: main) 1 related asset
261261
runtime modules 1.82 KiB 6 modules
262262
orphan modules 326 bytes [orphan] 1 module
263-
cacheable modules 540 KiB (javascript) 233 KiB (asset)
263+
cacheable modules 540 KiB (javascript) 9.88 KiB (asset)
264264
modules by path ./node_modules/ 539 KiB
265265
modules by path ./node_modules/css-loader/dist/runtime/*.js 2.38 KiB
266266
./node_modules/css-loader/dist/runtime/api.js 1.57 KiB [built] [code generated]
267267
./node_modules/css-loader/dist/runtime/getUrl.js 830 bytes [built] [code generated]
268268
./node_modules/lodash/lodash.js 530 KiB [built] [code generated]
269269
./node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js 6.67 KiB [built] [code generated]
270-
modules by path ./src/ 1.45 KiB (javascript) 233 KiB (asset)
271-
./src/index.js + 1 modules 795 bytes [built] [code generated]
272-
./src/icon.png 42 bytes (javascript) 233 KiB (asset) [built] [code generated]
270+
modules by path ./src/ 1.45 KiB (javascript) 9.88 KiB (asset)
271+
./src/index.js + 1 modules 794 bytes [built] [code generated]
272+
./src/icon.png 42 bytes (javascript) 9.88 KiB (asset) [built] [code generated]
273273
./node_modules/css-loader/dist/cjs.js!./src/style.css 648 bytes [built] [code generated]
274-
webpack 5.4.0 compiled successfully in 5879 ms
274+
webpack 5.4.0 compiled successfully in 1972 ms
275275
```
276276

277-
If all went well, you should now see your icon as a repeating background, as well as an `img` element beside our `Hello webpack` text. If you inspect this element, you'll see that the actual filename has changed to something like `3b7bf087cbac835e6f7d.png`. This means webpack found our file in the `src` folder and processed it!
277+
If all went well, you should now see your icon as a repeating background, as well as an `img` element beside our `Hello webpack` text. If you inspect this element, you'll see that the actual filename has changed to something like `29822eaa871e8eadeaa4.png`. This means webpack found our file in the `src` folder and processed it!
278278

279279

280280
## Loading Fonts
@@ -359,27 +359,27 @@ $ npm run build
359359

360360
...
361361
[webpack-cli] Compilation finished
362-
assets by status 233 KiB [cached] 1 asset
362+
assets by status 9.88 KiB [cached] 1 asset
363363
assets by info 33.2 KiB [immutable]
364364
asset 55055dbfc7c6a83f60ba.woff 18.8 KiB [emitted] [immutable] [from: src/my-font.woff] (auxiliary name: main)
365365
asset 8f717b802eaab4d7fb94.woff2 14.5 KiB [emitted] [immutable] [from: src/my-font.woff2] (auxiliary name: main)
366366
asset bundle.js 73.7 KiB [emitted] [minimized] (name: main) 1 related asset
367367
runtime modules 1.82 KiB 6 modules
368368
orphan modules 326 bytes [orphan] 1 module
369-
cacheable modules 541 KiB (javascript) 266 KiB (asset)
369+
cacheable modules 541 KiB (javascript) 43.1 KiB (asset)
370370
javascript modules 541 KiB
371371
modules by path ./node_modules/ 539 KiB
372372
modules by path ./node_modules/css-loader/dist/runtime/*.js 2.38 KiB 2 modules
373373
./node_modules/lodash/lodash.js 530 KiB [built] [code generated]
374374
./node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js 6.67 KiB [built] [code generated]
375375
modules by path ./src/ 1.98 KiB
376-
./src/index.js + 1 modules 795 bytes [built] [code generated]
376+
./src/index.js + 1 modules 794 bytes [built] [code generated]
377377
./node_modules/css-loader/dist/cjs.js!./src/style.css 1.21 KiB [built] [code generated]
378-
asset modules 126 bytes (javascript) 266 KiB (asset)
379-
./src/icon.png 42 bytes (javascript) 233 KiB (asset) [built] [code generated]
378+
asset modules 126 bytes (javascript) 43.1 KiB (asset)
379+
./src/icon.png 42 bytes (javascript) 9.88 KiB (asset) [built] [code generated]
380380
./src/my-font.woff2 42 bytes (javascript) 14.5 KiB (asset) [built] [code generated]
381381
./src/my-font.woff 42 bytes (javascript) 18.8 KiB (asset) [built] [code generated]
382-
webpack 5.4.0 compiled successfully in 3763 ms
382+
webpack 5.4.0 compiled successfully in 2142 ms
383383
```
384384

385385
Open up `dist/index.html` again and see if our `Hello webpack` text has changed to the new font. If all is well, you should see the changes.
@@ -716,14 +716,14 @@ __project__
716716
|- bundle.js
717717
|- index.html
718718
|- /src
719-
- |- data.xml
720719
- |- data.csv
720+
- |- data.json5
721721
- |- data.toml
722+
- |- data.xml
722723
- |- data.yaml
723-
- |- data.json5
724+
- |- icon.png
724725
- |- my-font.woff
725726
- |- my-font.woff2
726-
- |- icon.png
727727
- |- style.css
728728
|- index.js
729729
|- /node_modules
@@ -837,7 +837,7 @@ __src/index.js__
837837
And remove those dependencies we added before:
838838

839839
```bash
840-
npm rm csv-loader xml-loader toml yamljs json5
840+
npm uninstall css-loader csv-loader json5 style-loader toml xml-loader yamljs
841841
```
842842

843843
## Next guide

src/content/guides/development.md

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ __webpack.config.js__
3434
module.exports = {
3535
+ mode: 'development',
3636
entry: {
37-
app: './src/index.js',
37+
index: './src/index.js',
3838
print: './src/print.js',
3939
},
4040
plugins: [
@@ -71,7 +71,7 @@ __webpack.config.js__
7171
module.exports = {
7272
mode: 'development',
7373
entry: {
74-
app: './src/index.js',
74+
index: './src/index.js',
7575
print: './src/print.js',
7676
},
7777
+ devtool: 'inline-source-map',
@@ -104,15 +104,15 @@ Run an `npm run build`, it should compile to something like this:
104104
``` bash
105105
...
106106
[webpack-cli] Compilation finished
107-
asset app.bundle.js 1.38 MiB [emitted] (name: app)
107+
asset index.bundle.js 1.38 MiB [emitted] (name: index)
108108
asset print.bundle.js 6.25 KiB [emitted] (name: print)
109-
asset index.html 276 bytes [emitted]
109+
asset index.html 272 bytes [emitted]
110110
runtime modules 1.9 KiB 9 modules
111111
cacheable modules 530 KiB
112-
./src/index.js 407 bytes [built] [code generated]
112+
./src/index.js 406 bytes [built] [code generated]
113113
./src/print.js 83 bytes [built] [code generated]
114114
./node_modules/lodash/lodash.js 530 KiB [built] [code generated]
115-
webpack 5.4.0 compiled successfully in 759 ms
115+
webpack 5.4.0 compiled successfully in 706 ms
116116
```
117117

118118
Now open the resulting `index.html` file in your browser. Click the button and look in your console where the error is displayed. The error should say something like this:
@@ -134,8 +134,8 @@ It quickly becomes a hassle to manually run `npm run build` every time you want
134134
There are a couple of different options available in webpack that help you automatically compile your code whenever it changes:
135135

136136
1. webpack's [Watch Mode](/configuration/watch/#watch)
137-
2. webpack-dev-server
138-
3. webpack-dev-middleware
137+
2. [webpack-dev-server](https://github.com/webpack/webpack-dev-server)
138+
3. [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware)
139139

140140
In most cases, you probably would want to use `webpack-dev-server`, but let's explore all of the above options.
141141

@@ -164,9 +164,7 @@ __package.json__
164164
"license": "ISC",
165165
"devDependencies": {
166166
"clean-webpack-plugin": "^3.0.0",
167-
"css-loader": "^5.0.1",
168167
"html-webpack-plugin": "^4.5.0",
169-
"style-loader": "^2.0.0",
170168
"webpack": "^5.4.0",
171169
"webpack-cli": "^4.2.0"
172170
},
@@ -188,7 +186,7 @@ __webpack.config.js__
188186
module.exports = {
189187
mode: 'development',
190188
entry: {
191-
app: './src/index.js',
189+
index: './src/index.js',
192190
print: './src/print.js',
193191
},
194192
devtool: 'inline-source-map',
@@ -245,7 +243,7 @@ __webpack.config.js__
245243
module.exports = {
246244
mode: 'development',
247245
entry: {
248-
app: './src/index.js',
246+
index: './src/index.js',
249247
print: './src/print.js',
250248
},
251249
devtool: 'inline-source-map',
@@ -290,9 +288,7 @@ __package.json__
290288
"license": "ISC",
291289
"devDependencies": {
292290
"clean-webpack-plugin": "^3.0.0",
293-
"css-loader": "^5.0.1",
294291
"html-webpack-plugin": "^4.5.0",
295-
"style-loader": "^2.0.0",
296292
"webpack": "^5.4.0",
297293
"webpack-cli": "^4.2.0",
298294
"webpack-dev-server": "^3.11.0"
@@ -332,7 +328,7 @@ __webpack.config.js__
332328
module.exports = {
333329
mode: 'development',
334330
entry: {
335-
app: './src/index.js',
331+
index: './src/index.js',
336332
print: './src/print.js',
337333
},
338334
devtool: 'inline-source-map',
@@ -416,13 +412,11 @@ __package.json__
416412
"license": "ISC",
417413
"devDependencies": {
418414
"clean-webpack-plugin": "^3.0.0",
419-
"css-loader": "^5.0.1",
420415
"express": "^4.17.1",
421416
"html-webpack-plugin": "^4.5.0",
422-
"style-loader": "^2.0.0",
423417
"webpack": "^5.4.0",
424418
"webpack-cli": "^4.2.0",
425-
"webpack-dev-middleware": "^4.0.0",
419+
"webpack-dev-middleware": "^4.0.2",
426420
"webpack-dev-server": "^3.11.0"
427421
},
428422
"dependencies": {
@@ -436,20 +430,20 @@ Now in your terminal run `npm run server`, it should give you an output similar
436430
``` bash
437431
Example app listening on port 3000!
438432
...
439-
<i> [webpack-dev-middleware] asset app.bundle.js 1.38 MiB [emitted] (name: app)
433+
<i> [webpack-dev-middleware] asset index.bundle.js 1.38 MiB [emitted] (name: index)
440434
<i> asset print.bundle.js 6.25 KiB [emitted] (name: print)
441-
<i> asset index.html 278 bytes [emitted]
435+
<i> asset index.html 274 bytes [emitted]
442436
<i> runtime modules 1.9 KiB 9 modules
443437
<i> cacheable modules 530 KiB
444-
<i> ./src/index.js 407 bytes [built] [code generated]
438+
<i> ./src/index.js 406 bytes [built] [code generated]
445439
<i> ./src/print.js 83 bytes [built] [code generated]
446440
<i> ./node_modules/lodash/lodash.js 530 KiB [built] [code generated]
447-
<i> webpack 5.4.0 compiled successfully in 672 ms
441+
<i> webpack 5.4.0 compiled successfully in 709 ms
448442
<i> [webpack-dev-middleware] Compiled successfully.
449443
<i> [webpack-dev-middleware] Compiling...
450444
<i> [webpack-dev-middleware] assets by status 1.38 MiB [cached] 2 assets
451445
<i> cached modules 530 KiB (javascript) 1.9 KiB (runtime) [cached] 12 modules
452-
<i> webpack 5.4.0 compiled successfully in 14 ms
446+
<i> webpack 5.4.0 compiled successfully in 19 ms
453447
<i> [webpack-dev-middleware] Compiled successfully.
454448
```
455449

src/content/guides/getting-started.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ contributors:
2727

2828
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.
2929

30-
W> The minimum Node.js version to run webpack 5 is 10.13.0 (LTS)
30+
W> The minimum supported Node.js version to run webpack 5 is 10.13.0 (LTS)
3131

3232
## Basic Setup
3333

34-
First let's create a directory, initialize npm, [install webpack locally](/guides/installation/#local-installation), and install the webpack-cli (the tool used to run webpack on the command line):
34+
First let's create a directory, initialize npm, [install webpack locally](/guides/installation/#local-installation), and install the [`webpack-cli`](https://github.com/webpack/webpack-cli) (the tool used to run webpack on the command line):
3535

3636
``` bash
3737
mkdir webpack-demo
@@ -129,7 +129,7 @@ Let's use webpack to manage these scripts instead.
129129

130130
## Creating a Bundle
131131

132-
First we'll tweak our directory structure slightly, separating the "source" code (`/src`) from our "distribution" code (`/dist`). The "source" code is the code that we'll write and edit. The "distribution" code is the minimized and optimized `output` of our build process that will eventually be loaded in the browser. Tweak the directory structure as follows:
132+
First we'll tweak our directory structure slightly, separating the "source" code (`./src`) from our "distribution" code (`./dist`). The "source" code is the code that we'll write and edit. The "distribution" code is the minimized and optimized `output` of our build process that will eventually be loaded in the browser. Tweak the directory structure as follows:
133133

134134
__project__
135135

@@ -151,7 +151,7 @@ npm install --save lodash
151151

152152
T> When installing a package that will be bundled into your production bundle, you should use `npm install --save`. If you're installing a package for development purposes (e.g. a linter, testing libraries, etc.) then you should use `npm install --save-dev`. More information can be found in the [npm documentation](https://docs.npmjs.com/cli/install).
153153

154-
Now, lets import `lodash` in our script:
154+
Now, let's import `lodash` in our script:
155155

156156
__src/index.js__
157157

@@ -171,7 +171,7 @@ __src/index.js__
171171
document.body.appendChild(component());
172172
```
173173

174-
Now, since we'll be bundling our scripts, we have to update our `index.html` file. Let's remove the lodash `<script>`, as we now `import` it, and modify the other `<script>` tag to load the bundle, instead of the raw `/src` file:
174+
Now, since we'll be bundling our scripts, we have to update our `index.html` file. Let's remove the lodash `<script>`, as we now `import` it, and modify the other `<script>` tag to load the bundle, instead of the raw `./src` file:
175175

176176
__dist/index.html__
177177

@@ -202,16 +202,13 @@ runtime modules 1000 bytes 5 modules
202202
cacheable modules 530 KiB
203203
./src/index.js 257 bytes [built] [code generated]
204204
./node_modules/lodash/lodash.js 530 KiB [built] [code generated]
205-
webpack 5.4.0 compiled successfully in 3619 ms
205+
webpack 5.4.0 compiled successfully in 1851 ms
206206
```
207207

208-
T> Your output may vary a bit, but if the build is successful then you are good to go. Also, don't worry about the warning, we'll tackle that later.
208+
T> Your output may vary a bit, but if the build is successful then you are good to go.
209209

210210
Open `index.html` from the `dist` directory in your browser and, if everything went right, you should see the following text: `'Hello webpack'`.
211211

212-
W> If you are getting a syntax error in the middle of minified JavaScript when opening `index.html` in the browser, set [`development mode`](/configuration/mode/#mode-development) and run `npx webpack` again. This is related to running `npx webpack` on latest Node.js (v12.5+) instead of [LTS version](https://nodejs.org/en/).
213-
214-
215212
## Modules
216213

217214
The [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [`export`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) statements have been standardized in [ES2015](https://babeljs.io/docs/en/learn/). They are supported in most of the browsers at this moment, however there are some browsers that don't recognize the new syntax. But don't worry, webpack does support them out of the box.
@@ -261,7 +258,7 @@ runtime modules 1000 bytes 5 modules
261258
cacheable modules 530 KiB
262259
./src/index.js 257 bytes [built] [code generated]
263260
./node_modules/lodash/lodash.js 530 KiB [built] [code generated]
264-
webpack 5.4.0 compiled successfully in 3516 ms
261+
webpack 5.4.0 compiled successfully in 1934 ms
265262
```
266263

267264
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.
@@ -276,7 +273,7 @@ Given it's not particularly fun to run a local copy of webpack from the CLI, we
276273
__package.json__
277274

278275
``` diff
279-
{
276+
{
280277
"name": "webpack-demo",
281278
"version": "1.0.0",
282279
"description": "",
@@ -299,7 +296,7 @@ __package.json__
299296
}
300297
```
301298

302-
Now the `npm run build` command can be used in place of the `npx` command we used earlier. Note that within `scripts` we can reference locally installed npm packages by name the same way we did with `npx`. This convention is the standard in most npm-based projects because it allows all contributors to use the same set of common scripts (each with flags like `--config` if necessary).
299+
Now the `npm run build` command can be used in place of the `npx` command we used earlier. Note that within `scripts` we can reference locally installed npm packages by name the same way we did with `npx`. This convention is the standard in most npm-based projects because it allows all contributors to use the same set of common scripts.
303300

304301
Now run the following command and see if your script alias works:
305302

@@ -314,7 +311,7 @@ runtime modules 1000 bytes 5 modules
314311
cacheable modules 530 KiB
315312
./src/index.js 257 bytes [built] [code generated]
316313
./node_modules/lodash/lodash.js 530 KiB [built] [code generated]
317-
webpack 5.4.0 compiled successfully in 3764 ms
314+
webpack 5.4.0 compiled successfully in 1940 ms
318315
```
319316

320317
T> Custom parameters can be passed to webpack by adding two dashes between the `npm run build` command and your parameters, e.g. `npm run build -- --color`.

0 commit comments

Comments
 (0)