Skip to content

Instantly share code, notes, and snippets.

@wietseva
Created February 17, 2018 15:43
Show Gist options
  • Save wietseva/ce824e3b09504131055e76a550e918ea to your computer and use it in GitHub Desktop.
Save wietseva/ce824e3b09504131055e76a550e918ea to your computer and use it in GitHub Desktop.

Revisions

  1. wietseva created this gist Feb 17, 2018.
    32 changes: 32 additions & 0 deletions extendPluginOptions.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    const fs = require('fs')
    const isObject = val => val && typeof val === 'object'

    let pluginOptions = null
    module.exports = (api, cb) => {

    // Look up pluginOptions from the vue.config.js file
    // only do this once when its not yet defined
    const vueConfig = api.resolve('vue.config.js')
    if (!pluginOptions && fs.existsSync(vueConfig)) {
    let projectOptions = require(vueConfig)
    if (isObject(projectOptions.pluginOptions)) {
    pluginOptions = projectOptions.pluginOptions
    } else {
    pluginOptions = {}
    }
    }

    api.extendPackage((pkg) => {

    // extend pluginOptions
    // with those already defined in the pkg
    if (isObject(pkg.vue) && isObject(pkg.vue.pluginOptions)) {
    Object.assign(pluginOptions, pkg.vue.pluginOptions)
    }

    pluginOptions = cb(pluginOptions)
    return {
    vue: { pluginOptions }
    }
    })
    }