Skip to content

Commit da4d0b2

Browse files
committed
feat: relex transpile includes + new transpileDependencies option
BREAKING CHANGE: To include a dependency for Babel transpilation, tapping babel-loader and adding .include() will no longer work. Use the new transpileDependencies option instead.
1 parent 718ba3c commit da4d0b2

File tree

9 files changed

+37
-36
lines changed

9 files changed

+37
-36
lines changed

docs/config.md

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ module.exports = {
2525
// https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only
2626
compiler: false,
2727

28+
// babel-loader skips node_module deps by default.
29+
// explicitly transpile a dependency with this option.
30+
transpileDependencies: [/* string or regex */],
31+
2832
// tweak internal webpack configuration.
2933
// see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
3034
chainWebpack: () => {},

packages/@vue/cli-plugin-babel/README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66

77
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 `.babelrc` to use any other Babel presets or plugins.
88

9-
By default, `babel-loader` is only applied to files inside `src` and `tests` directories. If you wish to explicitly transpile a dependency module, you will need to configure webpack in `vue.config.js`:
9+
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`:
1010

1111
``` js
1212
module.exports = {
13-
chainWebpack: config => {
14-
config
15-
.rule('js')
16-
.include
17-
.add(/module-to-transpile/)
18-
}
13+
transpileDependencies: [
14+
// can be string or regex
15+
'my-dep',
16+
/other-dep/
17+
]
1918
}
2019
```
2120

packages/@vue/cli-plugin-babel/index.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
module.exports = (api, options) => {
2-
const useThreads = process.env.NODE_ENV === 'production' && options.parallel
1+
module.exports = (api, {
2+
parallel,
3+
transpileDependencies
4+
}) => {
5+
const useThreads = process.env.NODE_ENV === 'production' && parallel
36
const cacheDirectory = api.resolve('node_modules/.cache/cache-loader')
47

58
api.chainWebpack(webpackConfig => {
69
const jsRule = webpackConfig.module
710
.rule('js')
811
.test(/\.jsx?$/)
9-
.include
10-
.add(api.resolve('src'))
11-
.add(api.resolve('tests'))
12+
.exclude
13+
.add(filepath => {
14+
// check if this is something the user explicitly wants to transpile
15+
if (transpileDependencies.some(dep => filepath.match(dep))) {
16+
return false
17+
}
18+
// always trasnpile js in vue files
19+
if (/\.vue\.jsx?$/.test(filepath)) {
20+
return false
21+
}
22+
// Don't transpile node_modules
23+
return /node_modules/.test(filepath)
24+
})
1225
.end()
1326
.use('cache-loader')
1427
.loader('cache-loader')

packages/@vue/cli-plugin-eslint/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ module.exports = (api, { lintOnSave }) => {
55
webpackConfig.module
66
.rule('eslint')
77
.pre()
8-
.include
9-
.add(api.resolve('src'))
10-
.add(api.resolve('tests'))
8+
.exclude
9+
.add(/node_modules/)
1110
.end()
1211
.test(/\.(vue|(j|t)sx?)$/)
1312
.use('eslint-loader')

packages/@vue/cli-plugin-typescript/README.md

-14
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,6 @@ TypeScript can be configured via `tsconfig.json`.
1010

1111
This plugin can be used alongside `@vue/cli-plugin-babel`. When used with Babel, this plugin will output ES2015 and delegate the rest to Babel for auto polyfill based on browser targets.
1212

13-
By default, `ts-loader` is only applied to files inside `src` and `tests` directories. If you wish to explicitly transpile a dependency module, you will need to configure webpack in `vue.config.js`:
14-
15-
``` js
16-
module.exports = {
17-
chainWebpack: config => {
18-
config
19-
.module
20-
.rule('ts')
21-
.include
22-
.add(/module-to-transpile/)
23-
}
24-
}
25-
```
26-
2713
## Injected Commands
2814

2915
If opted to use [TSLint](https://palantir.github.io/tslint/) during project creation, `vue-cli-service lint` will be injected.

packages/@vue/cli-plugin-typescript/__tests__/tsPluginESLint.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jest.setTimeout(10000)
33
const create = require('@vue/cli-test-utils/createTestProject')
44

55
test('should work', async () => {
6-
const project = await create('ts-lint', {
6+
const project = await create('ts-eslint', {
77
plugins: {
88
'@vue/cli-plugin-eslint': {
99
config: 'prettier'

packages/@vue/cli-plugin-typescript/__tests__/tsPluginTSLint.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jest.setTimeout(10000)
33
const create = require('@vue/cli-test-utils/createTestProject')
44

55
test('should work', async () => {
6-
const project = await create('ts-lint', {
6+
const project = await create('ts-tslint', {
77
plugins: {
88
'@vue/cli-plugin-typescript': {
99
tsLint: true
@@ -34,7 +34,7 @@ test('should work', async () => {
3434
})
3535

3636
test('should not fix with --no-fix option', async () => {
37-
const project = await create('ts-lint-nofix', {
37+
const project = await create('ts-tslint-nofix', {
3838
plugins: {
3939
'@vue/cli-plugin-typescript': {
4040
tsLint: true

packages/@vue/cli-plugin-typescript/index.js

-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ module.exports = (api, {
1919
const tsRule = config.module
2020
.rule('ts')
2121
.test(/\.tsx?$/)
22-
.include
23-
.add(api.resolve('src'))
24-
.add(api.resolve('tests'))
25-
.end()
2622

2723
const vueLoader = config.module
2824
.rule('vue')

packages/@vue/cli-service/lib/options.js

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const schema = createSchema(joi => joi.object({
44
baseUrl: joi.string(),
55
outputDir: joi.string(),
66
compiler: joi.boolean(),
7+
transpileDependencies: joi.array(),
78
productionSourceMap: joi.boolean(),
89
vueLoader: joi.object(),
910
parallel: joi.boolean(),
@@ -55,6 +56,9 @@ exports.defaults = () => ({
5556
// boolean, use full build?
5657
compiler: false,
5758

59+
// deps to transpile
60+
transpileDependencies: [/* string or regex */],
61+
5862
// vue-loader options
5963
vueLoader: {
6064
preserveWhitespace: false,

0 commit comments

Comments
 (0)