You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/concepts/loaders.md
+39-3Lines changed: 39 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,47 @@ contributors:
6
6
- ev1stensberg
7
7
- SpaceK33z
8
8
- gangachris
9
+
- simon04
9
10
---
10
11
11
12
Loaders are transformations that are applied on a resource file of your application. They are functions (running in Node.js) that take the source of a resource file as the parameter and return the new source.
12
13
13
-
For example, you can use loaders to tell webpack to load a CSS file or to convert TypeScript to JavaScript.
14
+
## Example
15
+
16
+
For example, you can use loaders to tell webpack to load a CSS file or to convert TypeScript to JavaScript. Firstly, install the corresponding loaders:
17
+
18
+
```
19
+
npm install --save-dev css-loader
20
+
npm install --save-dev ts-loader
21
+
```
22
+
23
+
Secondly, configure in your `webpack.config.js` that for every `.css` file the `css-loader` should be used and analogously for `.ts` files and the `ts-loader`:
@@ -28,9 +64,9 @@ functions (loaders). Users now have more flexibility to include fine-grained log
28
64
29
65
## Resolving Loaders
30
66
31
-
Loaders are [resolved similar to modules](/concepts/module-resolution/). A loader module is expected to export a function and to be written in Node.js compatible JavaScript. In the common case you manage loaders with npm, but you can also have loaders as files in your app.
67
+
Loaders follow the standard [module resolution](/concepts/module-resolution/). In most cases you will be loaders from the [module path](/concepts/module-resolution/#module-paths) (think `npm install`, `node_modules`).
32
68
33
-
### Referencing Loaders
69
+
[How to write a loader?](/development/how-to-write-a-loader) A loader module is expected to export a function and to be written in Node.js compatible JavaScript. In the common case you manage loaders with npm, but you can also have loaders as files in your app.
34
70
35
71
By convention, loaders are usually named as `XXX-loader`, where `XXX` is the context name. For example, `json-loader`.
Copy file name to clipboardExpand all lines: content/loaders/index.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,8 @@ contributors:
10
10
11
11
As explained in detail on the [concepts page](/concepts/loaders), loaders are transformations that are applied on a resource file of your application. Loaders allow you to, for example, configure how webpack should handle a CSS file.
12
12
13
+
?> Move the general usage documentation to the [concepts page](/concepts/loaders) and focus here on describing the available loaders (similar to [plugins](/plugins)).
14
+
13
15
A loader is typically a npm package, which you can install as a development dependency:
0 commit comments