Skip to content

Make the current command's name available to plugins #2692

Closed
@m0dch3n

Description

@m0dch3n

What problem does this feature solve?

I'm currently developing a vue cli 3 plugin, to add cordova, to a vue project. For the serve and build, I created new commands in my generator.js

api.extendPackage({
    scripts: {
      'cordova-serve-android': 'vue-cli-service cordova-serve-android',
      'cordova-build-android': 'vue-cli-service cordova-build-android',
      'cordova-serve-ios': 'vue-cli-service cordova-serve-ios',
      'cordova-build-ios': 'vue-cli-service cordova-build-ios',
      'cordova-serve-browser': 'vue-cli-service cordova-serve-browser',
      'cordova-build-browser': 'vue-cli-service cordova-build-browser'
    },

And in my index new defaultModes for theses commands:

const defaultModes = {
  'cordova-serve-android': 'cordova-serve-android',
  'cordova-build-android': 'cordova-build-android',
  'cordova-serve-ios': 'cordova-serve-ios',
  'cordova-build-ios': 'cordova-build-ios',
  'cordova-serve-browser': 'cordova-serve-browser',
  'cordova-build-browser': 'cordova-build-browser'
}

The problem is now, if I ran vue-cli-service cordova-build-android, my process.env.NODE_ENV is development, because of loadEnv.

Setting my defaultModes to :

const defaultModes = {
  'cordova-serve-android': 'development',
  'cordova-build-android': 'production',
  'cordova-serve-ios': 'development',
  'cordova-build-ios': 'production',
  'cordova-serve-browser': 'development',
  'cordova-build-browser': 'production'
}

would correctly set the mode, however, in my plugin, during

api.chainWebpack(webpackConfig => {
}

and

api.configureDevServer(app => {
}

I no longer know, which mode (android, ios, browser), I'm using then.

My Plugin is available under https://github.com/m0dch3n/vue-cli-plugin-cordova to better understand, what I'm talking here about.

What does the proposed API look like?

It would be great, to have:

api.service.commandName = 'cordova-build-android'

i.e. if I ran vue-cli-service cordova-build-android

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions