Skip to content

Commit 06866ca

Browse files
authored
Merge pull request #4 from webpack/master
1117
2 parents 485bb6f + f94c9e4 commit 06866ca

File tree

5 files changed

+256
-200
lines changed

5 files changed

+256
-200
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

0 commit comments

Comments
 (0)