Skip to content

Commit d212dcd

Browse files
author
Guillaume Chau
committed
feat: package.json: vuePlugins.resolveFrom option, closes #1815
1 parent ab64240 commit d212dcd

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

docs/guide/plugins-and-presets.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ vue add vuex
6161

6262
If a plugin is already installed, you can skip the installation and only invoke its generator with the `vue invoke` command. The command takes the same arguments as `vue add`.
6363

64+
::: tip
65+
If for some reason your plugins are listed in a `package.json` file other than the one located in your project, you can set the `vuePlugins.resolveFrom` option in the project `package.json` with the path to the folder containing the other `package.json` file.
66+
67+
For example, if you have a `.config/package.json` file:
68+
69+
```json
70+
{
71+
"vuePlugins": {
72+
"resolveFrom": ".config"
73+
}
74+
}
75+
```
76+
:::
77+
6478
## Presets
6579

6680
A Vue CLI preset is a JSON object that contains pre-defined options and plugins for creating a new project so that the user don't have to go through the prompts to select them.

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ module.exports = class Service {
3636
}, {})
3737
}
3838

39-
resolvePkg (inlinePkg) {
39+
resolvePkg (inlinePkg, context = this.context) {
4040
if (inlinePkg) {
4141
return inlinePkg
42-
} else if (fs.existsSync(path.join(this.context, 'package.json'))) {
43-
return readPkg.sync({ cwd: this.context })
42+
} else if (fs.existsSync(path.join(context, 'package.json'))) {
43+
const pkg = readPkg.sync({ cwd: context })
44+
if (pkg.vuePlugins && pkg.vuePlugins.resolveFrom) {
45+
return this.resolvePkg(null, path.resolve(context, pkg.vuePlugins.resolveFrom))
46+
}
47+
return pkg
4448
} else {
4549
return {}
4650
}

packages/@vue/cli/lib/invoke.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require('fs')
1+
const fs = require('fs-extra')
22
const path = require('path')
33
const execa = require('execa')
44
const chalk = require('chalk')
@@ -43,7 +43,11 @@ function getPkg (context) {
4343
if (!fs.existsSync(pkgPath)) {
4444
throw new Error(`package.json not found in ${chalk.yellow(context)}`)
4545
}
46-
return loadModule(pkgPath, context, true)
46+
const pkg = fs.readJsonSync(pkgPath)
47+
if (pkg.vuePlugins && pkg.vuePlugins.resolveFrom) {
48+
return getPkg(path.resolve(context, pkg.vuePlugins.resolveFrom))
49+
}
50+
return pkg
4751
}
4852

4953
async function invoke (pluginName, options = {}, context = process.cwd()) {

0 commit comments

Comments
 (0)