Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

True dynamic single-file components #11417

Closed
ccleve opened this issue May 28, 2020 · 3 comments
Closed

True dynamic single-file components #11417

ccleve opened this issue May 28, 2020 · 3 comments

Comments

@ccleve
Copy link

ccleve commented May 28, 2020

What problem does this feature solve?

I've got an app where third parties can create plugins. I'd like them to be able to create those plugins as single file components, which get pulled in and displayed just like built-in components. Right now, the only way for them to do it is to create a component in this form:

{
template: "<div>stuff</div>",
props: ...
etc.
}

This is awkward, plus there is no easy way to include styles.

More details: https://stackoverflow.com/questions/62035019/load-vue-single-file-component-dynamically-at-runtime

I think that the logic to do this exists, but it's in vue-loader, and really intended for use with Webpack. Webpack is not designed for use at runtime.

What does the proposed API look like?

<template>
  <div>
    The component goes here:
    <component :is="pluginComponent"></component>
  </div>
</template>
<script>
import { compileSFC } from "vue-template-compiler";
export default {
  data() {
    return {
      pluginComponent: null
    };
  },
  mounted() {
    // fetch code from some external source here
    let code = "<template><div>hello</div></template><style>some styles</style><script>some code</script>";
    let comp = compileSFC(code);
    this.pluginComponent = comp;
  }
};
</script>
@posva
Copy link
Member

posva commented May 28, 2020

There are already tools to achieve the compilation process that exists inside vue-loader: https://github.com/vuejs?q=compiler&type=&language=

@posva posva closed this as completed May 28, 2020
@ccleve
Copy link
Author

ccleve commented May 29, 2020

Ok, but there isn't sufficient documentation to actually use them. There are no examples.

I went through some rollup code looking for some, but even the basic import generates a ton of compile errors, mostly pertaining to consolidate.js:

import { createDefaultCompiler } from "@vue/component-compiler";

Please don't mark this closed without adding a simple usage example. The example could be added to the README, and also used to answer this person's question: vuejs/vue-component-compiler#93

@ccleve
Copy link
Author

ccleve commented May 29, 2020

@posva Wanted to make sure you saw my comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants