Skip to content

Commit af37eea

Browse files
update loaders & update plugins
1 parent 957d82d commit af37eea

24 files changed

+1048
-667
lines changed

src/content/loaders/babel-loader.md

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,37 @@ repo: https://github.com/babel/babel-loader
66
---
77

88

9+
10+
911
This package allows transpiling JavaScript files using [Babel](https://github.com/babel/babel) and [webpack](https://github.com/webpack/webpack).
1012

11-
__Notes:__ Issues with the output should be reported on the babel [issue tracker](https://github.com/babel/babel/issues).
13+
**Note**: Issues with the output should be reported on the Babel [Issues](https://github.com/babel/babel/issues) tracker.
1214

1315
## Install
1416

15-
> webpack 3.x | babel-loader 8.x | babel 7.x
17+
> webpack 4.x | babel-loader 8.x | babel 7.x
1618
1719
```bash
18-
npm install "babel-loader@^8.0.0-beta" @babel/core @babel/preset-env webpack
20+
npm install -D babel-loader @babel/core @babel/preset-env webpack
1921
```
2022

21-
> webpack 3.x babel-loader 7.x | babel 6.x
23+
> webpack 4.x | babel-loader 7.x | babel 6.x
2224
2325
```bash
24-
npm install babel-loader babel-core babel-preset-env webpack
26+
npm install -D babel-loader@7 babel-core babel-preset-env webpack
2527
```
2628

2729
## Usage
2830

29-
[Documentation: Using loaders](https://webpack.js.org/loaders/)
31+
webpack documentation: [Loaders](https://webpack.js.org/loaders/)
3032

3133
Within your webpack configuration object, you'll need to add the babel-loader to the list of modules, like so:
3234

3335
```javascript
3436
module: {
3537
rules: [
3638
{
37-
test: /\.js$/,
39+
test: /\.m?js$/,
3840
exclude: /(node_modules|bower_components)/,
3941
use: {
4042
loader: 'babel-loader',
@@ -49,22 +51,21 @@ module: {
4951

5052
##
5153

52-
See the `babel` [options](https://babeljs.io/docs/usage/api/#options).
54+
See the `babel` [options](https://babeljs.io/docs/en/options).
5355

54-
55-
You can pass options to the loader by using the [options property](https://webpack.js.org/configuration/module/#rule-options-rule-query):
56+
You can pass options to the loader by using the [`options`](https://webpack.js.org/configuration/module/#rule-options-rule-query) property:
5657

5758
```javascript
5859
module: {
5960
rules: [
6061
{
61-
test: /\.js$/,
62+
test: /\.m?js$/,
6263
exclude: /(node_modules|bower_components)/,
6364
use: {
6465
loader: 'babel-loader',
6566
options: {
6667
presets: ['@babel/preset-env'],
67-
plugins: [require('@babel/plugin-proposal-object-rest-spread')]
68+
plugins: ['@babel/plugin-proposal-object-rest-spread']
6869
}
6970
}
7071
}
@@ -74,48 +75,44 @@ module: {
7475

7576
This loader also supports the following loader-specific option:
7677

77-
* `cacheDirectory`: Default `false`. When set, the given directory will be used to cache the results of the loader. Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run. If the value is blank (`loader: 'babel-loader?cacheDirectory'`) or `true` (`loader: babel-loader?cacheDirectory=true`) the loader will use the default cache directory in `node_modules/.cache/babel-loader` or fallback to the default OS temporary file directory if no `node_modules` folder could be found in any root directory.
78+
* `cacheDirectory`: Default `false`. When set, the given directory will be used to cache the results of the loader. Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run. If the value is blank (`loader: 'babel-loader?cacheDirectory'`) or `true` (`loader: 'babel-loader?cacheDirectory=true'`), the loader will use the default cache directory in `node_modules/.cache/babel-loader` or fallback to the default OS temporary file directory if no `node_modules` folder could be found in any root directory.
79+
80+
* `cacheIdentifier`: Default is a string composed by the `babel-core`'s version, the `babel-loader`'s version, the contents of `.babelrc` file if it exists, and the value of the environment variable `BABEL_ENV` with a fallback to the `NODE_ENV` environment variable. This can be set to a custom value to force cache busting if the identifier changes.
7881

79-
* `cacheIdentifier`: Default is a string composed by the babel-core's version, the babel-loader's version, the contents of .babelrc file if it exists and the value of the environment variable `BABEL_ENV` with a fallback to the `NODE_ENV` environment variable. This can be set to a custom value to force cache busting if the identifier changes.
82+
* `cacheCompression`: Default `true`. When set, each Babel transform output will be compressed with Gzip. If you want to opt-out of cache compression, set it to `false` -- your project may benefit from this if it transpiles thousands of files.
8083

81-
* `babelrc`: Default `true`. When `false`, no options from `.babelrc` files will be used; only the options passed to
82-
`babel-loader` will be used.
84+
* `customize`: Default `null`. The path of a module that exports a `custom` callback [like the one that you'd pass to `.custom()`](#customized-loader). Since you already have to make a new file to use this, it is recommended that you instead use `.custom` to create a wrapper loader. Only use this is you _must_ continue using `babel-loader` directly, but still want to customize.
8385

84-
__Note:__ The `sourceMap` option is ignored, instead sourceMaps are automatically enabled when webpack is configured to use them (via the `devtool` config option).
86+
**Note**: The `sourceMap` option is ignored. Instead, source maps are automatically enabled when webpack is configured to use them (via the [`devtool`](https://webpack.js.org/configuration/devtool/#devtool) config option).
8587

8688
## Troubleshooting
8789

8890
### babel-loader is slow!
8991

90-
Make sure you are transforming as few files as possible. Because you are probably
91-
matching `/\.js$/`, you might be transforming the `node_modules` folder or other unwanted
92-
source.
92+
Make sure you are transforming as few files as possible. Because you are probably matching `/\.m?js$/`, you might be transforming the `node_modules` folder or other unwanted source.
9393

9494
To exclude `node_modules`, see the `exclude` option in the `loaders` config as documented above.
9595

96-
You can also speed up babel-loader by as much as 2x by using the `cacheDirectory` option.
97-
This will cache transformations to the filesystem.
96+
You can also speed up babel-loader by as much as 2x by using the `cacheDirectory` option. This will cache transformations to the filesystem.
9897

99-
### babel is injecting helpers into each file and bloating my code!
98+
### Babel is injecting helpers into each file and bloating my code!
10099

101-
babel uses very small helpers for common functions such as `_extend`. By default
102-
this will be added to every file that requires it.
100+
Babel uses very small helpers for common functions such as `_extend`. By default, this will be added to every file that requires it.
103101

104-
You can instead require the babel runtime as a separate module to avoid the duplication.
102+
You can instead require the Babel runtime as a separate module to avoid the duplication.
105103

106-
The following configuration disables automatic per-file runtime injection in babel, instead
107-
requiring `babel-plugin-transform-runtime` and making all helper references use it.
104+
The following configuration disables automatic per-file runtime injection in Babel, requiring `babel-plugin-transform-runtime` instead and making all helper references use it.
108105

109106
See the [docs](https://babeljs.io/docs/plugins/transform-runtime/) for more information.
110107

111-
**NOTE:** You must run `npm install @babel/plugin-transform-runtime --save-dev` to include this in your project and `babel-runtime` itself as a dependency with `npm install @babel/runtime --save`.
108+
**NOTE**: You must run `npm install -D @babel/plugin-transform-runtime` to include this in your project and `babel-runtime` itself as a dependency with `npm install @babel/runtime`.
112109

113110
```javascript
114111
rules: [
115-
// the 'transform-runtime' plugin tells babel to require the runtime
116-
// instead of inlining it.
112+
// the 'transform-runtime' plugin tells Babel to
113+
// require the runtime instead of inlining it.
117114
{
118-
test: /\.js$/,
115+
test: /\.m?js$/,
119116
exclude: /(node_modules|bower_components)/,
120117
use: {
121118
loader: 'babel-loader',
@@ -128,9 +125,9 @@ rules: [
128125
]
129126
```
130127

131-
#### **NOTE:** transform-runtime & custom polyfills (e.g. Promise library)
128+
#### **NOTE**: transform-runtime & custom polyfills (e.g. Promise library)
132129

133-
Since [babel-plugin-transform-runtime](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-runtime) includes a polyfill that includes a custom [regenerator runtime](https://github.com/facebook/regenerator/blob/master/packages/regenerator-runtime/runtime.js) and [core.js](https://github.com/zloirock/core-js), the following usual shimming method using `webpack.ProvidePlugin` will not work:
130+
Since [babel-plugin-transform-runtime](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-runtime) includes a polyfill that includes a custom [regenerator-runtime](https://github.com/facebook/regenerator/blob/master/packages/regenerator-runtime/runtime.js) and [core-js](https://github.com/zloirock/core-js), the following usual shimming method using `webpack.ProvidePlugin` will not work:
134131

135132
```javascript
136133
// ...
@@ -174,23 +171,23 @@ require('@babel/runtime/core-js/promise').default = require('bluebird');
174171
require('./app');
175172
```
176173

177-
### The node API for `babel` has been moved to `babel-core`.
174+
### The Node.js API for `babel` has been moved to `babel-core`.
178175

179-
If you receive this message it means that you have the npm package `babel` installed and use the short notation of the loader in the webpack config (which is not valid anymore as of webpack 2.x):
180-
```js
176+
If you receive this message, it means that you have the npm package `babel` installed and are using the short notation of the loader in the webpack config (which is not valid anymore as of webpack 2.x):
177+
```javascript
181178
{
182-
test: /\.js$/,
179+
test: /\.m?js$/,
183180
loader: 'babel',
184181
}
185182
```
186183

187-
Webpack then tries to load the `babel` package instead of the `babel-loader`.
184+
webpack then tries to load the `babel` package instead of the `babel-loader`.
188185

189-
To fix this you should uninstall the npm package `babel` as it is deprecated in babel v6. (instead install `babel-cli` or `babel-core`)
186+
To fix this, you should uninstall the npm package `babel`, as it is deprecated in Babel v6. (Instead, install `babel-cli` or `babel-core`.)
190187
In the case one of your dependencies is installing `babel` and you cannot uninstall it yourself, use the complete name of the loader in the webpack config:
191-
```js
188+
```javascript
192189
{
193-
test: /\.js$/,
190+
test: /\.m?js$/,
194191
loader: 'babel-loader',
195192
}
196193
```
@@ -204,9 +201,14 @@ of Babel's configuration for each file that it processes.
204201
`babel` so that tooling can ensure that it using exactly the same `@babel/core`
205202
instance as the loader itself.
206203

204+
In cases where you want to customize without actually having a file to call `.custom`, you
205+
may also pass the `customize` option with a string pointing at a file that exports
206+
your `custom` callback function.
207+
207208
### Example
208209

209210
```js
211+
// Export from "./my-custom-loader.js" or whatever you want.
210212
module.exports = require("babel-loader").custom(babel => {
211213
function myPlugin() {
212214
return {
@@ -226,7 +228,7 @@ module.exports = require("babel-loader").custom(babel => {
226228
};
227229
},
228230

229-
// Passed Babel's 'PartialConfig' object.
231+
// Passed Babel's 'PartialConfig' object.
230232
config(cfg) {
231233
if (cfg.hasFilesystemConfig()) {
232234
// Use the normal config
@@ -254,6 +256,20 @@ module.exports = require("babel-loader").custom(babel => {
254256
});
255257
```
256258

259+
```js
260+
// And in your Webpack config
261+
module.exports = {
262+
// ..
263+
module: {
264+
rules: [{
265+
// ...
266+
loader: path.join(__dirname, 'my-custom-loader.js'),
267+
// ...
268+
}]
269+
}
270+
};
271+
```
272+
257273
### `customOptions(options: Object): { custom: Object, loader: Object }`
258274

259275
Given the loader's options, split custom options out of `babel-loader`'s
@@ -271,4 +287,5 @@ be passed to `babel.transform`.
271287
Given Babel's result object, allow loaders to make additional tweaks to it.
272288

273289

274-
## [License](https://couto.mit-license.org/)
290+
## License
291+
[MIT](https://couto.mit-license.org/)

src/content/loaders/bundle-loader.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Bundle loader for webpack
1212
npm i bundle-loader --save
1313
```
1414

15-
## <a href="https://webpack.js.org/concepts/loaders">Usage</a>
15+
## Usage
1616

1717
**webpack.config.js**
1818
```js

src/content/loaders/config-loader.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ repo: https://github.com/webpack-contrib/config-loader
1414

1515

1616

17+
DEPRECATED. `webpack-command` is also deprecated. Please use `webpack-cli`. If any features were not implemented in `webpack-cli` feel free to create issue.
18+
19+
Why deprecated `webpack-command` ?
20+
- `webpack-cli` is very stable and have more features.
21+
- Two CLIs are misleading for developers.
22+
- Hard to maintain two package with same purpose.
23+
- The author stopped developing the package.
24+
- Most of the features are already implemented in `webpack-cli`.
25+
26+
Thanks for using `webpack`! We apologize for the inconvenience. In the future, we will avoid such situations.
27+
_____
28+
1729
A webpack configuration loader.
1830

1931
This module utilizes [`cosmiconfig`](https://github.com/davidtheclark/cosmiconfig)

src/content/loaders/css-loader.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141

4242
##
4343

44-
You can also use the css-loader results directly as string, such as in Angular's component style.
44+
You can also use the css-loader results directly as a string, such as in Angular's component style.
4545

4646
**webpack.config.js**
4747
```js
@@ -106,6 +106,12 @@ url(~module/image.png) => require('module/image.png')
106106

107107
### `import`
108108

109+
To import styles from a node module path, prefix it with a `~`:
110+
111+
```css
112+
@import '~module/styles.css';
113+
```
114+
109115
To disable `@import` resolving by `css-loader` set the option to `false`
110116

111117
```css
@@ -128,7 +134,7 @@ The syntax `:local(.className)` can be used to declare `className` in the local
128134

129135
With `:local` (without brackets) local mode can be switched on for this selector. `:global(.className)` can be used to declare an explicit global selector. With `:global` (without brackets) global mode can be switched on for this selector.
130136

131-
The loader replaces local selectors with unique identifiers. The choosen unique identifiers are exported by the module.
137+
The loader replaces local selectors with unique identifiers. The chosen unique identifiers are exported by the module.
132138

133139
```css
134140
:local(.className) { background: red; }
@@ -153,7 +159,7 @@ exports.locals = {
153159
}
154160
```
155161

156-
CamelCase is recommended for local selectors. They are easier to use in the within the imported JS module.
162+
CamelCase is recommended for local selectors. They are easier to use within the imported JS module.
157163

158164
`url()` URLs in block scoped (`:local .abc`) rules behave like requests in modules.
159165

@@ -271,9 +277,9 @@ You can also specify the absolute path to your custom `getLocalIdent` function t
271277

272278
To include source maps set the `sourceMap` option.
273279

274-
I. e. the extract-text-webpack-plugin can handle them.
280+
I.e. the extract-text-webpack-plugin can handle them.
275281

276-
They are not enabled by default because they expose a runtime overhead and increase in bundle size (JS source maps do not). In addition to that relative paths are buggy and you need to use an absolute public path which include the server URL.
282+
They are not enabled by default because they expose a runtime overhead and increase in bundle size (JS source maps do not). In addition to that relative paths are buggy and you need to use an absolute public path which includes the server URL.
277283

278284
**webpack.config.js**
279285
```js
@@ -318,7 +324,7 @@ import { className } from 'file.css';
318324

319325
### `importLoaders`
320326

321-
The query parameter `importLoaders` allows to configure how many loaders before `css-loader` should be applied to `@import`ed resources.
327+
The query parameter `importLoaders` allows you to configure how many loaders before `css-loader` should be applied to `@import`ed resources.
322328

323329
**webpack.config.js**
324330
```js
@@ -338,7 +344,7 @@ The query parameter `importLoaders` allows to configure how many loaders before
338344
}
339345
```
340346

341-
This may change in the future, when the module system (i. e. webpack) supports loader matching by origin.
347+
This may change in the future when the module system (i. e. webpack) supports loader matching by origin.
342348

343349
## Examples
344350

@@ -369,7 +375,7 @@ module.exports = {
369375

370376
### Extract
371377

372-
For production builds it's recommended to extract the CSS from your bundle being able to use parallel loading of CSS/JS resources later on.
378+
For production builds it's recommended to extract the CSS from your bundle being able to use parallel loading of CSS/JS resources later on.
373379
This can be achieved by using the [mini-css-extract-plugin](/plugins/mini-css-extract-plugin/) to extract the CSS when running in production mode.
374380

375381
## Maintainers
@@ -435,11 +441,14 @@ This can be achieved by using the [mini-css-extract-plugin](/plugins/mini-css-ex
435441
[deps]: https://david-dm.org/webpack-contrib/css-loader.svg
436442
[deps-url]: https://david-dm.org/webpack-contrib/css-loader
437443

438-
[tests]: http://img.shields.io/travis/webpack-contrib/css-loader.svg
439-
[tests-url]: https://travis-ci.org/webpack-contrib/css-loader
444+
[tests]: https://img.shields.io/circleci/project/github/webpack-contrib/css-loader.svg
445+
[tests-url]: https://circleci.com/gh/webpack-contrib/css-loader
440446

441447
[cover]: https://codecov.io/gh/webpack-contrib/css-loader/branch/master/graph/badge.svg
442448
[cover-url]: https://codecov.io/gh/webpack-contrib/css-loader
443449

444450
[chat]: https://badges.gitter.im/webpack/webpack.svg
445451
[chat-url]: https://gitter.im/webpack/webpack
452+
453+
[size]: https://packagephobia.now.sh/badge?p=css-loader
454+
[size-url]: https://packagephobia.now.sh/result?p=css-loader

src/content/loaders/eslint-loader.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ See the [eslint docs](http://eslint.org/docs/developer-guide/nodejs-api#cliengin
104104
This option will enable
105105
[ESLint autofix feature](http://eslint.org/docs/user-guide/command-line-interface#fix).
106106

107-
**Be careful: this option might cause webpack to enter an infinite build loop if
108-
some issues cannot be fixed properly.**
107+
**Be careful: this option will change source files.**
109108

110109
#### `cache` (default: false)
111110

src/content/loaders/expose-loader.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ module: {
102102
}
103103
```
104104

105-
The [`require.resolve`](https://nodejs.org/api/all.html#modules_require_resolve)
105+
The [`require.resolve`](https://nodejs.org/api/modules.html#modules_require_resolve_request_options)
106106
call is a Node.js function (unrelated to `require.resolve` in webpack
107107
processing). `require.resolve` gives you the
108108
absolute path to the module (`"/.../app/node_modules/react/react.js"`). So the
@@ -113,7 +113,7 @@ bundle.
113113

114114
Please take a moment to read our contributing guidelines if you haven't yet done so.
115115

116-
#### [CONTRIBUTING](https://raw.githubusercontent.com/webpack-contrib/expose-loader/master/.github/CONTRIBUTING)
116+
#### [CONTRIBUTING](https://raw.githubusercontent.com/webpack-contrib/expose-loader/master/.github/CONTRIBUTING.md)
117117

118118
## License
119119

@@ -135,4 +135,4 @@ Please take a moment to read our contributing guidelines if you haven't yet done
135135
[cover-url]: https://codecov.io/gh/webpack-contrib/expose-loader
136136

137137
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
138-
[chat-url]: https://gitter.im/webpack/webpack
138+
[chat-url]: https://gitter.im/webpack/webpack

0 commit comments

Comments
 (0)