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
This loader also supports the following loader-specific option:
76
77
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.
78
81
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.
80
83
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.
83
85
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).
85
87
86
88
## Troubleshooting
87
89
88
90
### babel-loader is slow!
89
91
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.
93
93
94
94
To exclude `node_modules`, see the `exclude` option in the `loaders` config as documented above.
95
95
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.
98
97
99
-
### babel is injecting helpers into each file and bloating my code!
98
+
### Babel is injecting helpers into each file and bloating my code!
100
99
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.
103
101
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.
105
103
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.
108
105
109
106
See the [docs](https://babeljs.io/docs/plugins/transform-runtime/) for more information.
110
107
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`.
112
109
113
110
```javascript
114
111
rules: [
115
-
// the 'transform-runtime' plugin tells babel to require the runtime
Since [babel-plugin-transform-runtime](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-runtime) includes a polyfill that includes a custom [regeneratorruntime](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:
### The node API for `babel` has been moved to `babel-core`.
174
+
### The Node.js API for `babel` has been moved to `babel-core`.
178
175
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
181
178
{
182
-
test:/\.js$/,
179
+
test:/\.m?js$/,
183
180
loader:'babel',
184
181
}
185
182
```
186
183
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`.
188
185
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`.)
190
187
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
192
189
{
193
-
test:/\.js$/,
190
+
test:/\.m?js$/,
194
191
loader:'babel-loader',
195
192
}
196
193
```
@@ -204,9 +201,14 @@ of Babel's configuration for each file that it processes.
204
201
`babel` so that tooling can ensure that it using exactly the same `@babel/core`
205
202
instance as the loader itself.
206
203
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
+
207
208
### Example
208
209
209
210
```js
211
+
// Export from "./my-custom-loader.js" or whatever you want.
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
+
17
29
A webpack configuration loader.
18
30
19
31
This module utilizes [`cosmiconfig`](https://github.com/davidtheclark/cosmiconfig)
To import styles from a node module path, prefix it with a `~`:
110
+
111
+
```css
112
+
@import'~module/styles.css';
113
+
```
114
+
109
115
To disable `@import` resolving by `css-loader` set the option to `false`
110
116
111
117
```css
@@ -128,7 +134,7 @@ The syntax `:local(.className)` can be used to declare `className` in the local
128
134
129
135
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.
130
136
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.
132
138
133
139
```css
134
140
:local(.className) { background: red; }
@@ -153,7 +159,7 @@ exports.locals = {
153
159
}
154
160
```
155
161
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.
157
163
158
164
`url()` URLs in block scoped (`:local .abc`) rules behave like requests in modules.
159
165
@@ -271,9 +277,9 @@ You can also specify the absolute path to your custom `getLocalIdent` function t
271
277
272
278
To include source maps set the `sourceMap` option.
273
279
274
-
I.e. the extract-text-webpack-plugin can handle them.
280
+
I.e. the extract-text-webpack-plugin can handle them.
275
281
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.
277
283
278
284
**webpack.config.js**
279
285
```js
@@ -318,7 +324,7 @@ import { className } from 'file.css';
318
324
319
325
### `importLoaders`
320
326
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.
322
328
323
329
**webpack.config.js**
324
330
```js
@@ -338,7 +344,7 @@ The query parameter `importLoaders` allows to configure how many loaders before
338
344
}
339
345
```
340
346
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.
342
348
343
349
## Examples
344
350
@@ -369,7 +375,7 @@ module.exports = {
369
375
370
376
### Extract
371
377
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.
373
379
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.
374
380
375
381
## Maintainers
@@ -435,11 +441,14 @@ This can be achieved by using the [mini-css-extract-plugin](/plugins/mini-css-ex
0 commit comments