From 2a3d08ce7f704a0a135fbb70afd114e74811f8e5 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Thu, 12 Jul 2018 01:03:46 +0200 Subject: [PATCH] feat: package.json: vueCli.resolvePlugins option, closes #1815 --- docs/guide/plugins-and-presets.md | 14 ++++++++++++++ packages/@vue/cli-service/lib/Service.js | 10 +++++++--- packages/@vue/cli/lib/invoke.js | 8 ++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/docs/guide/plugins-and-presets.md b/docs/guide/plugins-and-presets.md index 8d423d9f5e..7dcbe3391b 100644 --- a/docs/guide/plugins-and-presets.md +++ b/docs/guide/plugins-and-presets.md @@ -57,6 +57,20 @@ vue add vuex 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`. +::: tip +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 `vueCli.resolvePlugins` option in the project `package.json` with the path to the folder containing the other `package.json` file. + +For example, if you have a `.config/package.json` file: + +```json +{ + "vueCli": { + "resolvePlugins": ".config" + } +} +``` +::: + ## Presets 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. diff --git a/packages/@vue/cli-service/lib/Service.js b/packages/@vue/cli-service/lib/Service.js index 045156842b..72bd16a032 100644 --- a/packages/@vue/cli-service/lib/Service.js +++ b/packages/@vue/cli-service/lib/Service.js @@ -36,11 +36,15 @@ module.exports = class Service { }, {}) } - resolvePkg (inlinePkg) { + resolvePkg (inlinePkg, context = this.context) { if (inlinePkg) { return inlinePkg - } else if (fs.existsSync(path.join(this.context, 'package.json'))) { - return readPkg.sync({ cwd: this.context }) + } else if (fs.existsSync(path.join(context, 'package.json'))) { + const pkg = readPkg.sync({ cwd: context }) + if (pkg.vueCli && pkg.vueCli.resolvePlugins) { + return this.resolvePkg(null, path.resolve(context, pkg.vueCli.resolvePlugins)) + } + return pkg } else { return {} } diff --git a/packages/@vue/cli/lib/invoke.js b/packages/@vue/cli/lib/invoke.js index bda2fdf919..539ff2a1e0 100644 --- a/packages/@vue/cli/lib/invoke.js +++ b/packages/@vue/cli/lib/invoke.js @@ -1,4 +1,4 @@ -const fs = require('fs') +const fs = require('fs-extra') const path = require('path') const execa = require('execa') const chalk = require('chalk') @@ -43,7 +43,11 @@ function getPkg (context) { if (!fs.existsSync(pkgPath)) { throw new Error(`package.json not found in ${chalk.yellow(context)}`) } - return loadModule(pkgPath, context, true) + const pkg = fs.readJsonSync(pkgPath) + if (pkg.vueCli && pkg.vueCli.resolvePlugins) { + return getPkg(path.resolve(context, pkg.vueCli.resolvePlugins)) + } + return pkg } async function invoke (pluginName, options = {}, context = process.cwd()) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy