GithubHelp home page GithubHelp logo

Comments (6)

justin-schroeder avatar justin-schroeder commented on September 27, 2024 2

Thanks for the feedback @pi0! We'll make these changes soon.

from formkit.

justin-schroeder avatar justin-schroeder commented on September 27, 2024 1

@pi0 — I refactored most of the module in this most recent push — including using resolvePath and reducing the templating significantly. It now only has 2 simple template outputs. Honestly I would love to get rid of the template all together, but as far as I can tell there is no way to pass functions and other non serializable data to a nuxt plugin from a nuxt module using addPlugin (or is there?).

FormKit uses lots of user-defined functions in its configuration (like plugin functions for example) — so as far as I know, I still need to use the template to "manually" write those import statements (is my assumption true?)

from formkit.

pi0 avatar pi0 commented on September 27, 2024

Amazing work @justin-schroeder ! Added two comments to 0cbfab5 hopefully solving template issue.

from formkit.

justin-schroeder avatar justin-schroeder commented on September 27, 2024

@pi0 — ok, played around with the nuxt.options.alias a bit to try and fully remove the template — but I've fallen short. I need to import a named import (import { defaultConfig } from '@fomrkit/core') based on the module option option.defaultConfig. So for example, the final template output could be 1 of 3 variations:

1. No configFile or detected config file provided:

import { defineNuxtPlugin } from '#app'
import { plugin, defaultConfig } from '@formkit/vue'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(plugin, defaultConfig)
})

2. formkit.config.(ts|mjs|js) exists and defaultConfig is true (default)

import { defineNuxtPlugin } from '#app'
import { plugin, defaultConfig } from '@formkit/vue'
import config from './path/to/formkit.config.ts'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(plugin, defaultConfig(config))
})

3. formkit.config.(ts|mjs|js) is false and defaultConfig is false

In this case they provide the entire config setup, so we don’t import defaultConfig at all:

import { defineNuxtPlugin } from '#app'
import { plugin } from '@formkit/vue'
import config from './path/to/formkit.config.ts'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(plugin, config)
})

If I understand correctly, I can alias import config from '#formkit-config' to be the path to formkit.config.ts file which solves 1 import question, but doesn't solve the variability of the named import { defaultConfig } from '@formkit/vue'. If users dont want the defaultConfig I dont want to import it since it includes a lot of default weight people may not want to absorb.

Is this a use case for keeping the template around, or are there other paths forward?

from formkit.

pi0 avatar pi0 commented on September 27, 2024

We can think of some ideas to alias config to an empty alias (like #empty) but we could also use a dynamic import template from the module:

addTemplate({
  filename: '#fromkit-config'
  getContents: () => { /* dynamic logic to generate exportstatement */ return 'export default ...' }
})

This way we can still avoid lodash template in plugin while having full control over logic using a template for config.

from formkit.

andrew-boyd avatar andrew-boyd commented on September 27, 2024

We've been able to remove the lodash templates in the latest release. Closing this one!

from formkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.