Skip to content

feat: when transpileDependencies is set to true, transpile all dependencies in node_modules #6354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 24, 2021
Prev Previous commit
Next Next commit
docs: update transpileDependencies documentation
  • Loading branch information
haoqunjiang committed Mar 18, 2021
commit e85c452c08f2feb24d343b25ab03e2bc942508c8
8 changes: 5 additions & 3 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@ Deprecated since Vue CLI 3.3, please use [`publicPath`](#publicPath) instead.

### transpileDependencies

- Type: `Array<string | RegExp>`
- Default: `[]`
- Type: `boolean | Array<string | RegExp>`
- Default: `false`

By default `babel-loader` ignores all files inside `node_modules`. You can enable this option to avoid unexpected untranspiled code from third-party dependencies.

By default `babel-loader` ignores all files inside `node_modules`. If you want to explicitly transpile a dependency with Babel, you can list it in this option.
Transpiling all the dependencies could slow down the build process, though. If build performance is a concern, you can explicitly transpile only some of the dependencies by passing an array of package names or name patterns to this option.

::: warning Jest config
This option is not respected by the [cli-unit-jest plugin](#jest), because in jest, we don't have to transpile code from `/node_modules` unless it uses non-standard features - Node >8.11 supports the latest ECMAScript features already.
Expand Down
4 changes: 3 additions & 1 deletion docs/core-plugins/babel.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

Uses Babel 7 + `babel-loader` + [@vue/babel-preset-app](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/babel-preset-app) by default, but can be configured via `babel.config.js` to use any other Babel presets or plugins.

By default, `babel-loader` excludes files inside `node_modules` dependencies. If you wish to explicitly transpile a dependency module, you will need to add it to the `transpileDependencies` option in `vue.config.js`:
By default, `babel-loader` excludes files inside `node_modules` dependencies. You can enable the `transpileDependencies` option in `vue.config.js` to transpile the dependencies. Or, if you want to only transpile some of the dependency modules, you can pass an array to the `transpileDependencies` option:

``` js
module.exports = {
// Set to `true` to transpile all dependencies.
// Or pass an array to transpile selectively.
transpileDependencies: [
// can be string or regex
'my-dep',
Expand Down
9 changes: 6 additions & 3 deletions docs/zh/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,13 @@ module.exports = {

### transpileDependencies

- Type: `Array<string | RegExp>`
- Default: `[]`
- Type: `boolean | Array<string | RegExp>`
- Default: `false`

默认情况下 `babel-loader` 会忽略所有 `node_modules` 中的文件。你可以启用本选项,以避免构建后的代码中出现未转译的第三方依赖。

不过,对所有的依赖都进行转译可能会降低构建速度。如果对构建性能有所顾虑,你可以只转译部分特定的依赖:给本选项传一个数组,列出需要转译的第三方包包名或正则表达式即可。

默认情况下 `babel-loader` 会忽略所有 `node_modules` 中的文件。如果你想要通过 Babel 显式转译一个依赖,可以在这个选项中列出来。

### productionSourceMap

Expand Down