vue3-sfc-loader icon indicating copy to clipboard operation
vue3-sfc-loader copied to clipboard

Support for Node environments

Open leviwheatcroft opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. No support for node environments

Describe the solution you'd like To be able to use vue3-sfc-loader in a node environment

Describe alternatives you've considered I have a working proof of concept

Additional context

This is related to #132 - if you try to use vue3-sfc-loader in a node environment you get a ReferenceError complaining that self is undefined.

This is pretty much because the built package is transpiled by webpack targetting browser environments.

I forked this repo, and added a webpack profile to transpile for node targets. It seems to be working as expected, but I'm unable to test this extensively and I have no idea if this is the best approach to obtain node support.

I guess I'm hoping for some feedback and / or guidance from the maintainers. Happy to work towards a pull request if you would like.

To make this work, you'll need to:

  • clone my repo
  • check out node-build branch
  • install dependencies and build according to the usual process
  • run npm link in your local vue3-sfc-compiler directory
  • run npm link vue3-sfc-compiler in your project directory
  • import the special node build as in `const { loadModule } = require('vue3-sfc-loader/dist/vue3-sfc-loader.node.js')

Additionally, you need to provide an options object as in loadModule(path, options) per the examples in this repo.

I would be happy to provide a repro if someone can suggest a code sandbox that allows you to create node projects?

leviwheatcroft avatar Jul 19 '23 23:07 leviwheatcroft

Hi leviwheatcroft, since Vue is a client-side framework, in which context do you need it for node ?

FranckFreiburger avatar Jan 06 '24 20:01 FranckFreiburger

nodejs bundle is available in the main branch (yarn run build-node)

FranckFreiburger avatar Jan 21 '24 17:01 FranckFreiburger

Awesome. Amazing. Thankyou.

Sorry I didn't reply earlier but support for node environments allows this module to build components for static sites. It's pretty great.

leviwheatcroft avatar Feb 25 '24 23:02 leviwheatcroft