Skip to content

Commit 5b0e392

Browse files
committed
fix: enable whitelist in exclude function
1 parent 874c196 commit 5b0e392

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

Diff for: docs/guide/pre-processors.md

+17
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,23 @@ npm install -D babel-core babel-loader
172172

173173
Configuration of Babel can be done via `.babelrc` or `babel-loader` options.
174174

175+
### Excluding node_modules
176+
177+
It is common to have `exclude: /node_modules/` for JS transpilation rules (e.g. `babel-loader`) that apply to `.js` files. Due to the inference change of v15, if you import a Vue SFC inside `node_modules`, its `<script>` part will be excluded from transpilation as well.
178+
179+
In order to ensure JS transpilation is applied to Vue SFCs in `node_modules`, you need to whitelist them by using an exclude function instead:
180+
181+
``` js
182+
{
183+
test: /\.js$/,
184+
loader: 'babel-loader',
185+
exclude: file => (
186+
/node_modules/.test(file) &&
187+
!/\.vue\.js/.test(file)
188+
)
189+
}
190+
```
191+
175192
## TypeScript
176193

177194
``` bash

Diff for: docs/migrating.md

+17
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ The benefit is that this same rule also applies to plain `*.less` imports from J
5757

5858
v15 also allows using non-serializable options for loaders, which was not possible in previous versions.
5959

60+
### Importing SFCs from Dependencies
61+
62+
It is common to have `exclude: /node_modules/` for JS transpilation rules (e.g. `babel-loader`) that apply to `.js` files. Due to the inference change of v15, if you import a Vue SFC inside `node_modules`, its `<script>` part will be excluded from transpilation as well.
63+
64+
In order to ensure JS transpilation is applied to Vue SFCs in `node_modules`, you need to whitelist them by using an exclude function instead:
65+
66+
``` js
67+
{
68+
test: /\.js$/,
69+
loader: 'babel-loader',
70+
exclude: file => (
71+
/node_modules/.test(file) &&
72+
!/\.vue\.js/.test(file)
73+
)
74+
}
75+
```
76+
6077
### Template Preprocessing
6178

6279
v14 and below uses [consolidate](https://github.com/tj/consolidate.js/) to compile `<template lang="xxx">`. v15 now applies preprocessing for them using webpack loaders instead.

Diff for: lib/plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function cloneRule (rule, normalizedRule) {
151151
if (resource && parsed.lang == null) {
152152
return false
153153
}
154-
const fakeResourcePath = `${currentResource.replace(/\.vue$/, '')}.${parsed.lang}`
154+
const fakeResourcePath = `${currentResource}.${parsed.lang}`
155155
if (resource && !resource(fakeResourcePath)) {
156156
return false
157157
}

0 commit comments

Comments
 (0)