Skip to content

Commit 4fe9f73

Browse files
LinusBorghaoqunjiang
authored andcommitted
feat: --skip-plugins (vuejs#4448)
Allow skipping of plugins from command line close vuejs#4262 close vuejs#3830 (cherry picked from commit fba2ad0)
1 parent 6f44f2a commit 4fe9f73

File tree

6 files changed

+92
-19
lines changed

6 files changed

+92
-19
lines changed

docs/guide/cli-service.md

+50-16
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ Usage: vue-cli-service serve [options] [entry]
4444
4545
Options:
4646
47-
--open open browser on server start
48-
--copy copy url to clipboard on server start
49-
--mode specify env mode (default: development)
50-
--host specify host (default: 0.0.0.0)
51-
--port specify port (default: 8080)
52-
--https use https (default: false)
47+
--open open browser on server start
48+
--copy copy url to clipboard on server start
49+
--mode specify env mode (default: development)
50+
--host specify host (default: 0.0.0.0)
51+
--port specify port (default: 8080)
52+
--https use https (default: false)
53+
--public specify the public network URL for the HMR client
54+
--skip-plugins comma-separated list of plugin names to skip for this run
5355
```
5456

5557
::: tip --copy
@@ -70,17 +72,20 @@ Usage: vue-cli-service build [options] [entry|pattern]
7072
7173
Options:
7274
73-
--mode specify env mode (default: production)
74-
--dest specify output directory (default: dist)
75-
--modern build app targeting modern browsers with auto fallback
76-
--target app | lib | wc | wc-async (default: app)
77-
--formats list of output formats for library builds (default: commonjs,umd,umd-min)
75+
--mode specify env mode (default: production)
76+
--dest specify output directory (default: dist)
77+
--modern build app targeting modern browsers with auto fallback
78+
--no-unsafe-inline build app without introducing inline scripts
79+
--target app | lib | wc | wc-async (default: app)
80+
--formats list of output formats for library builds (default: commonjs,umd,umd-min)
7881
--inline-vue include the Vue module in the final bundle of library or web component target
79-
--name name for lib or web-component mode (default: "name" in package.json or entry filename)
80-
--no-clean do not remove the dist directory before building the project
81-
--report generate report.html to help analyze bundle content
82-
--report-json generate report.json to help analyze bundle content
83-
--watch watch for changes
82+
--name name for lib or web-component mode (default: "name" in package.json or entry filename)
83+
--filename file name for output, only usable for 'lib' target (default: value of --name),
84+
--no-clean do not remove the dist directory before building the project
85+
--report generate report.html to help analyze bundle content
86+
--report-json generate report.json to help analyze bundle content
87+
--skip-plugins comma-separated list of plugin names to skip for this run
88+
--watch watch for changes
8489
```
8590

8691
`vue-cli-service build` produces a production-ready bundle in the `dist/` directory, with minification for JS/CSS/HTML and auto vendor chunk splitting for better caching. The chunk manifest is inlined into the HTML.
@@ -119,6 +124,35 @@ You can also learn about the available options of each command with:
119124
npx vue-cli-service help [command]
120125
```
121126

127+
## Skipping Plugins
128+
129+
Sometimes, you may want to not use a certain CLI Plugin when running a command. For example you might want to build a version of your app that doesn't include the PWA plugin. You can do that by passing the name of the plugin to the `--skip-plugins` option.
130+
131+
```bash
132+
npx vue-cli-service build --skip-plugins pwa
133+
```
134+
135+
::: tip
136+
This option is available for _every_ `vue-cli-service` command, including custom ones added by other plugins.
137+
:::
138+
139+
You can skip multiple plugins by passing their names as a comma-separated list:
140+
141+
```bash
142+
npx vue-cli-service build --skip-plugins pwa,apollo
143+
```
144+
145+
Plugin names are resolved the same way they are during install, as described [here](./plugins-and-presets.md#installing-plugins-in-an-existing-project)
146+
147+
``` bash
148+
# these are all equivalent
149+
npx vue-cli-service build --skip-plugins pwa
150+
151+
npx vue-cli-service build --skip-plugins @vue/pwa
152+
153+
npx vue-cli-service build --skip-plugins @vue/cli-plugin-pwa
154+
```
155+
122156
## Caching and Parallelization
123157

124158
- `cache-loader` is enabled for Vue/Babel/TypeScript compilations by default. Files are cached inside `node_modules/.cache` - if running into compilation issues, always try deleting the cache directory first.

packages/@vue/cli-service/__tests__/Service.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,27 @@ test('api: registerCommand', () => {
200200
expect(args).toEqual({ _: [], n: 1 })
201201
})
202202

203+
test('api: --skip-plugins', () => {
204+
let untouched = true
205+
const service = createMockService([{
206+
id: 'test-command',
207+
apply: api => {
208+
api.registerCommand('foo', _args => {
209+
return
210+
})
211+
}
212+
},
213+
{
214+
id: 'vue-cli-plugin-test-plugin',
215+
apply: api => {
216+
untouched = false
217+
}
218+
}], false)
219+
220+
service.run('foo', { 'skip-plugins': 'test-plugin' })
221+
expect(untouched).toEqual(true)
222+
})
223+
203224
test('api: defaultModes', () => {
204225
fs.writeFileSync('/.env.foo', `FOO=5\nBAR=6`)
205226
fs.writeFileSync('/.env.foo.local', `FOO=7\nBAZ=8`)

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const PluginAPI = require('./PluginAPI')
99
const dotenv = require('dotenv')
1010
const dotenvExpand = require('dotenv-expand')
1111
const defaultsDeep = require('lodash.defaultsdeep')
12-
const { warn, error, isPlugin, loadModule } = require('@vue/cli-shared-utils')
12+
const { warn, error, isPlugin, resolvePluginId, loadModule } = require('@vue/cli-shared-utils')
1313

1414
const { defaults, validate } = require('./options')
1515

@@ -32,6 +32,8 @@ module.exports = class Service {
3232
// When useBuiltIn === false, built-in plugins are disabled. This is mostly
3333
// for testing.
3434
this.plugins = this.resolvePlugins(plugins, useBuiltIn)
35+
// pluginsToSkip will be populated during run()
36+
this.pluginsToSkip = new Set()
3537
// resolve the default mode to use for each command
3638
// this is provided by plugins as module.exports.defaultModes
3739
// so we can get the information without actually applying the plugin.
@@ -77,6 +79,7 @@ module.exports = class Service {
7779

7880
// apply plugins.
7981
this.plugins.forEach(({ id, apply }) => {
82+
if (this.pluginsToSkip.has(id)) return
8083
apply(new PluginAPI(id, this), this.projectOptions)
8184
})
8285

@@ -132,6 +135,15 @@ module.exports = class Service {
132135
}
133136
}
134137

138+
setPluginsToSkip (args) {
139+
const skipPlugins = args['skip-plugins']
140+
const pluginsToSkip = skipPlugins
141+
? new Set(skipPlugins.split(',').map(id => resolvePluginId(id)))
142+
: new Set()
143+
144+
this.pluginsToSkip = pluginsToSkip
145+
}
146+
135147
resolvePlugins (inlinePlugins, useBuiltIn) {
136148
const idToPlugin = id => ({
137149
id: id.replace(/^.\//, 'built-in:'),
@@ -202,6 +214,9 @@ module.exports = class Service {
202214
// fallback to resolved default modes from plugins or development if --watch is defined
203215
const mode = args.mode || (name === 'build' && args.watch ? 'development' : this.modes[name])
204216

217+
// --skip-plugins arg may have plugins that should be skipped during init()
218+
this.setPluginsToSkip(args)
219+
205220
// load env variables, load user config, apply plugins
206221
this.init(mode)
207222

packages/@vue/cli-service/lib/commands/build/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module.exports = (api, options) => {
3636
'--no-clean': `do not remove the dist directory before building the project`,
3737
'--report': `generate report.html to help analyze bundle content`,
3838
'--report-json': 'generate report.json to help analyze bundle content',
39+
'--skip-plugins': `comma-separated list of plugin names to skip for this run`,
3940
'--watch': `watch for changes`
4041
}
4142
}, async (args, rawArgs) => {

packages/@vue/cli-service/lib/commands/inspect.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = (api, options) => {
1010
'--plugin <pluginName>': 'inspect a specific plugin',
1111
'--rules': 'list all module rule names',
1212
'--plugins': 'list all plugin names',
13-
'--verbose': 'show full function definitions in output'
13+
'--verbose': 'show full function definitions in output',
14+
'--skip-plugins': 'comma-separated list of plugin names to skip for this run'
1415
}
1516
},
1617
args => {

packages/@vue/cli-service/lib/commands/serve.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ module.exports = (api, options) => {
2323
'--host': `specify host (default: ${defaults.host})`,
2424
'--port': `specify port (default: ${defaults.port})`,
2525
'--https': `use https (default: ${defaults.https})`,
26-
'--public': `specify the public network URL for the HMR client`
26+
'--public': `specify the public network URL for the HMR client`,
27+
'--skip-plugins': `comma-separated list of plugin names to skip for this run`
2728
}
2829
}, async function serve (args) {
2930
info('Starting development server...')

0 commit comments

Comments
 (0)