Skip to content

Alias/helpers for extending config files #845

Open
@Akryum

Description

@Akryum

Proposal for enhancing Generator API with additional convenience methods. Edited by @yyx990803 to incorporate #846 & #892.

Extending entry file

// Generator
api.extendScript('./src/main', file => {
  // Import a file
  file.injectImport('{ apolloProvider }', './vue-apollo')
  // Direct import
  file.injectImport('./style.css')
  // Add an option to the instance
  file.injectRootOptions({
    provide: 'apolloProvider.provide()',
  })
})

As suggested in #892 this can be done by translating the API into extra data passed to EJS when rendering the entry template:

import Vue from 'vue'
import App from './App.vue'
<%_ if (options.router) { _%>
import router from './router'
<%_ } _%>
<%_ if (options.vuex) { _%>
import store from './store'
<%_ } _%>
<%_ for(const _import of injectedImports) { _%>
import <%= _import.bindings %> from '<%= _import.from %>'
<%_ } _%>

Vue.config.productionTip = false

new Vue({
  <%_ if (options.router) { _%>
  router,
  <%_ } _%>
  <%_ if (options.vuex) { _%>
  store,
  <%_ } _%>
  <%_ for(const option of injectedRootOptions) { _%>
  <%= option %>,
  <%_ } _%>
  render: h => h(App)
}).$mount('#app')

Extending .gitignore

// Generator
api.extendGitignore([
  '/live/',
])

Extending tsconfig.json

// Generator
api.extendTsConfig(...)

Aliases for Extending Other Config Files

These could be just aliases on top of extendPackage

// Generator
api.extendVueConfig(...)
api.extendBabelConfig(...)
api.extendPostCSSConfig(...)
api.extendESLintConfig(...)
api.extendJestConfig(...)
api.extendBrowsersList(...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureintend to implementThe team has the intention to implement this feature at some point. Contribution is also welcome.scope: plugin API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions