Chris Calo
Chris Calo

Reputation: 7838

How can I use .vue files in Node.js *without* a bundler like webpack?

I'm trying to find a simple server-side rendering solution for Vue.js, but every example or tutorial I've found has dependencies I don't want to include that overcomplicate things: usually webpack, Vue Router, and Vuex.

I'm looking for a solution that runs in Node.js and can render a .vue file to a string, including any other .vue files it may reference.

const sfcContent = fs.readFileSync("./app.vue", "utf-8");
const props = {
  foo: "bar",
};
const htmlString = await render(sfcContent, props);

console.log(htmlString);

async function render(sfcContent, props) {
  // this is the function I'm looking for
}

http-vue-loader looks promising, as it does roughly what I'm looking for except in the browser instead of Node.js.

Any ideas what I should try?

Upvotes: 0

Views: 157

Answers (1)

Tobias G.
Tobias G.

Reputation: 341

You could look into the compiler-utils package https://github.com/vuejs/component-compiler-utils

Although, this will still require some tinkering on your end so I'm not sure if it'll be the way to go if you don't want to overcomplicate things.

Upvotes: 1

Related Questions