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

feat: Vue 3 Support #997

Closed
crutch12 opened this issue Oct 13, 2020 · 58 comments
Closed

feat: Vue 3 Support #997

crutch12 opened this issue Oct 13, 2020 · 58 comments
Labels
enhancement New feature or request intend to implement Sometime in the next 2 major release this will be implemented

Comments

@crutch12
Copy link

To compile vue3 template we have to use @vue/compiler-sfc (because vue-template-compiler is for vue2 only).

vuejs/core#670 (comment)

I think this is an issue that should be fixed in vue-cli-plugin-vue-next by not including vue-template-compiler (which is for 2.x only)


So we have to replace parseComponent(...) from vue-template-compiler with parse(...).descriptor from @vue/compiler-sfc

Here:

  1. output = compiler.parseComponent(source)
  2. const customBlocks = parseComponent(fs.readFileSync(filepath, 'utf8')).customBlocks
@elevatebart
Copy link
Member

You are absolutely right, thanks for the recommendation.

It might not be enough. I will track the vue 3 compatibility work on this issue.

@elevatebart elevatebart added the bug Something isn't working label Oct 13, 2020
@elevatebart elevatebart changed the title feat(vue-docgen-api): Vue 3 Support feat: Vue 3 Support Oct 13, 2020
@elevatebart elevatebart added this to todo in vue-styleguidist via automation Oct 13, 2020
@elevatebart elevatebart added enhancement New feature or request intend to implement Sometime in the next 2 major release this will be implemented and removed bug Something isn't working labels Oct 13, 2020
@elevatebart
Copy link
Member

elevatebart commented Oct 13, 2020

As expected, the rewiring of the compiler was not enough.
Since Vue apps have a very different root in v2 and v3, this file needs to be re-wired.
https://github.com/vue-styleguidist/vue-styleguidist/blob/dev/packages/vue-styleguidist/src/client/utils/globalizeComponent.ts

This is how we do it in vue 3.
https://dev.to/jakedohm_34/registering-global-components-with-vue-3-2kgl

It would mean having one vue app per example block.
In each vue app, all components would be registered again.

@elevatebart
Copy link
Member

For the reasons above vue 3 compatibility means breaking changes in the way we use renderRootJsx.
Breaking changes mean a major version.

I suggest we use the "next" branch and the "@next" channel to deliver vue 3 compat.

@elevatebart
Copy link
Member

I hit a snag last time I tried which is I have to abandon TypeScript completely if I am to adopt vue 3.
Indeed, the TSX typings of vue 3 conflict with React's typings so one cannot have them both installed at the same time.

@crutch12
Copy link
Author

Classical TypeScript :/

image

@elevatebart
Copy link
Member

To be fair to TypeScript, that is classic Facebook/React.
TSX was made with the Facebook motto in mind: "Go fast and break things" pushing them to add the TSX typings as ambient, not caring about anyone that would need another version of these typings (like Vue or Svelte)

@crutch12
Copy link
Author

What can we do now?

@elevatebart
Copy link
Member

Hello @crutch12

I removed all TypeScript from the vue3 branch. I see your point.
Then I have to remove all tests because @testing-library/react imports react types which makes babel fail.

I was OK with no TypeScript until it is fixed but no tests at all, that's a bummer.
I have an issue posted on vue-next and a PR that goes with it.

Now, we wait.

@spaceemotion
Copy link

@elevatebart Are we still waiting on vuejs/core#1033? You said you would have some time on VueLand, did you manage to have an idea on how to approach this?

@elevatebart
Copy link
Member

Hello @spaceemotion

I found a solution that works and have not delivered it.

  1. going to vue3 is a deep breaking change, so I would like to use this opportunity to add breaking changes that have been asked for a long time. You can find a list of these changes in Next build vue3 #1002
  2. The idea of removing all unit tests and all types from vue-styleguidist is not acceptable to me. So, for now, we are still waiting.

If you are documenting your components in the style of vue-styleguidist, you still have options:

  • vue-docgen-api is already compatible with vue3. It does not detect everything but it works. I am very eager to get feedback with it.
  • Use vue-docgen-cli generates markdown files that can be consumed by any static site generator.
  • Complete it with vue-live@next for live examples and you can build your own vue 3 compatible tool

I hope this helps.

@spaceemotion
Copy link

Thanks for the tip! I only wanted to use vue-docgen-api anyways so that was perfect timing.

I incorporated it into a custom rollup plugin and it worked without any problems 🎉 (.vue files lang=typescript).

Will keep you posted while I explore the options/annotations 👍

@spaceemotion
Copy link

Alright, not sure if I should open up a new issue for this, but I just tried the following and it doesn't pick up the displayName or description (props work fine though):

// (do something up here with "typeof component")

/**
 * Buttons allow users to perform an action or to navigate to another page.
 * They have multiple styles for various needs, and are ideal for calling attention
 * to where a user needs to do something in order to move forward in a flow.
 *
 * @displayName Button
 * @group Form Elements
 */
const component = defineComponent({
  name: "DsButton",
  props: {},
});

export default component;

Gives me:

{
  "displayName": "DsButton",
  "exportName": "default",
  "description": "",
  "tags": {},
  "props": [],
  "slots": [
    {
      "name": "default"
    }
  ]
}

@elevatebart
Copy link
Member

There is an issue common to vue 2 if you assign the output instead of exporting it directly...
Let me fix this really quick..

In the meantime, this should work though.

/**
 * Buttons allow users to perform an action or to navigate to another page.
 * They have multiple styles for various needs, and are ideal for calling attention
 * to where a user needs to do something in order to move forward in a flow.
 *
 * @displayName Button
 * @group Form Elements
 */
export default defineComponent({
  name: "DsButton",
  props: {},
});

elevatebart added a commit that referenced this issue Nov 25, 2020
also valid for vue 3 defineComponent
cc #997
@Keyes
Copy link

Keyes commented Feb 24, 2021

Any news on Vue3 support so far? I enjoy using styleguidist way more than storybook for example, but it feels weird starting a new project now with Vue2 only because of that... :/

@elevatebart
Copy link
Member

@Keyes thanks for the kind words.

I am a bit swamped right now but it's moving. checkout the progress on the Pull Requests marked with the label next major

My plan is to support Vue3 in the next major version. I should be starting to work on it in March, for a release at the beginning of summer.

  • No more support for Vue 2
  • Use of typescript in examples
  • Monaco as the editor with an option to get back to the prism editor if you need lighter sites.
  • And hopefully sass compilation in SFC

@mambari
Copy link

mambari commented May 9, 2021

Hi @elevatebart
Thank you for your work.
Any news on Vue3 support (even beta that we can test) ?
Best regards,

@dvh91
Copy link

dvh91 commented Jan 18, 2022

@elevatebart Thanks! withDefaults indeed working great! Can you maybe assist with this one?

@shadow7412
Copy link

Should this still work with Vue 2? Or is there a specific version I should target for projects that haven't been updated yet?

@elevatebart
Copy link
Member

@shadow7412 It is unit-tested with vue2 (still) so everything should work with vue 2 and not vue 3.

Do you have any issue with a vue 2 project ?

@shadow7412
Copy link

shadow7412 commented Mar 12, 2022

I was getting an error that had something to do with vue sfcs. From memory it might have been unable to find @vue/compiler-sfcs... But I won't be able to get the exact errors until I get back to work on Tuesday.

@shadow7412
Copy link

shadow7412 commented Mar 15, 2022

@elevatebart sorry about the delay.

My current error when attempting to build for a Vue 2 project is Error: Cannot find module 'vue/compiler-sfc'. Attempting to run npm install vue/compiler-sfc directs me to log into github, then fails (I assume based on this it's a private package?).

My vue is at 2.6.14, and vue-styleguidist is at 4.44.18 in case that helps.

@bodograumann
Copy link
Contributor

@shadow7412 It should be @vue/compiler-sfc. Notice the @ at the front.

@shadow7412
Copy link

@shadow7412 It should be @vue/compiler-sfc. Notice the @ at the front.

In the npm command, the import, or both?

@fallsimply
Copy link

Both. The vue/compiler-sfc import was introduced in Vue 3

@shadow7412 It should be @vue/compiler-sfc. Notice the @ at the front.

In the npm command, the import, or both?

@elevatebart
Copy link
Member

And this is the package I use in docgen, to parse the sfc

@shadow7412
Copy link

Does that mean it should be listed as a dependency, assuming it was introduced in vue 3 and not backported?

@elevatebart
Copy link
Member

It should... I hope it is...

@elevatebart
Copy link
Member

It is

@shadow7412
Copy link

shadow7412 commented Mar 20, 2022

@elevatebart is it though?

This is an excerpt from package.json in `node_modules/vue-styleguidist`
"dependencies": {
 "@vxna/mini-html-webpack-template": "^1.0.0",
 "ast-types": "0.13.4",
 "classnames": "^2.3.1",
 "clean-webpack-plugin": "^3.0.0",
 "cli-progress": "^3.9.0",
 "clipboard-copy": "^3.2.0",
 "clsx": "^1.1.1",
 "codemirror": "^5.60.0",
 "common-dir": "^2.0.2",
 "copy-webpack-plugin": "^5.1.2",
 "core-js": "^3.9.1",
 "css-loader": "^2.1.1",
 "es6-object-assign": "^1.1.0",
 "es6-promise": "^4.2.8",
 "escodegen": "^1.14.3",
 "findup": "^0.1.5",
 "function.name-polyfill": "^1.0.6",
 "github-slugger": "^1.3.0",
 "glob": "^7.1.6",
 "glogg": "^1.0.2",
 "hash-sum": "^1.0.2",
 "is-directory": "^0.3.1",
 "javascript-stringify": "^1.6.0",
 "jss": "^10.6.0",
 "kleur": "^2.0.2",
 "leven": "^2.1.0",
 "loader-utils": "^1.4.0",
 "lodash": "^4.17.21",
 "lru-cache": "^4.1.5",
 "mini-html-webpack-plugin": "^3.1.3",
 "minimist": "^1.2.5",
 "prismjs": "^1.23.0",
 "prop-types": "^15.7.2",
 "q-i": "2.0.1",
 "qss": "^2.0.3",
 "react": "^17.0.2",
 "react-codemirror2": "^7.2.1",
 "react-dev-utils": "^12.0.0-next.47",
 "react-dom": "^17.0.2",
 "react-group": "^3.0.2",
 "react-icons": "^3.11.0",
 "react-lifecycles-compat": "^3.0.4",
 "react-simple-code-editor": "^0.11.0",
 "react-styleguidist": "^11.1.6",
 "rewrite-imports": "^2.0.3",
 "source-map": "0.6.1",
 "style-loader": "^1.3.0",
 "terser-webpack-plugin": "^2.3.8",
 "to-ast": "^1.0.0",
 "vue-docgen-api": "^4.44.22",
 "vue-inbrowser-compiler": "^4.44.22",
 "vue-inbrowser-compiler-utils": "^4.44.22",
 "webpack-dev-server": "^3.11.2",
 "webpack-merge": "^4.2.2"
},
"deprecated": false,
"description": "Vue components style guide generator",
"devDependencies": {
 "@babel/cli": "7.17.6",
 "@babel/core": "7.17.5",
 "@babel/plugin-proposal-class-properties": "7.16.7",
 "@babel/plugin-proposal-object-rest-spread": "7.17.3",
 "@babel/plugin-syntax-dynamic-import": "7.8.3",
 "@babel/plugin-transform-runtime": "7.17.0",
 "@babel/preset-env": "7.16.11",
 "@babel/preset-react": "7.16.7",
 "@babel/preset-typescript": "7.16.7",
 "@babel/runtime": "7.17.2",
 "@babel/types": "7.17.0",
 "@testing-library/react": "11.2.7",
 "@types/buble": "0.20.1",
 "@types/cli-progress": "1.8.1",
 "@types/copy-webpack-plugin": "4.4.4",
 "@types/doctrine": "0.0.5",
 "@types/escodegen": "0.0.7",
 "@types/loader-utils": "1.1.6",
 "@types/lodash": "4.14.178",
 "@types/mini-html-webpack-plugin": "2.2.2",
 "@types/prismjs": "1.16.6",
 "@types/pug": "2.0.6",
 "@types/react-dev-utils": "9.0.10",
 "@types/react-dom": "17.0.11",
 "@types/react-lifecycles-compat": "3.0.1",
 "@types/terser-webpack-plugin": "1.2.1",
 "@types/webpack": "4.41.32",
 "@types/webpack-dev-server": "3.11.6",
 "@types/webpack-merge": "4.1.5",
 "buble": "0.20.0",
 "concurrently": "4.1.2",
 "ejs": "2.7.4",
 "pug": "3.0.2",
 "strip-shebang": "1.0.2",
 "vue": "2.6.14",
 "vue-template-compiler": "2.6.14",
 "webpack": "4.46.0"
},

@shadow7412
Copy link

@shadow7412 It should be @vue/compiler-sfc. Notice the @ at the front.

I tried npm installing @vue/compiler-sfc, but I'm getting the exact same error. Note that the import I mentioned there is from this project rather than my own, so if it's wrong and supposed to be prefixed with a @ as you say, then I'm surprised this is working for anyone.

@elevatebart
Copy link
Member

First a quick detail about dependencies:

Vue-styleguidist depends on vue-docgen-api that depends on @vue/compiler-sfc and @vue/compiler-core.

@elevatebart
Copy link
Member

Second, can you please try and create a reproduction on a GitHub repo.

This is the best way I can help you.

@shadow7412
Copy link

Sorry about the delay - does this work for you? (Though I ended up with a different error message again... :/)

@elevatebart
Copy link
Member

@shadow7412 It does work for me, except I do not have a font-awesome pro account.

I was able to work around that, but do not get the error you mention about @vue/compiler-sfc.

What OS/ version of node/version of npm are you using?

@elevatebart
Copy link
Member

Also, when using the vue-cli, please use the cli-plugin. There is a lot of weird quirks about using vue-cli and it needs the plugin.

See this doc for more info.

@Psycarlo
Copy link

I have a vite-vue3-typescript project
When I install Vue Styleguidist
yarn add --dev vue-styleguidist
and then run
vue-styleguidist server
I get
Error: This version of vue-styleguidist is only compatible with Vue 2.

@StefanGhiban
Copy link

I have a vite-vue3-typescript project When I install Vue Styleguidist yarn add --dev vue-styleguidist and then run vue-styleguidist server I get Error: This version of vue-styleguidist is only compatible with Vue 2.

Same project, same issue.

@Gagydzer
Copy link

Is it work with vue 3 or not?
Tried with @vue/cli 4.5.15 and it requiries vue-template-compiler

@elevatebart
Copy link
Member

Is it work with vue 3 or not?

Tried with @vue/cli 4.5.15 and it requiries vue-template-compiler

Not yet.

@elevatebart
Copy link
Member

I believe I will be able to add alpha support for vue 3 around the week of July 4th.

Expect a new major version (5.0.0-alpha) to be released mid July. Then we shall see ;)

@elevatebart
Copy link
Member

Compatibility with Vue 3 was achieved without breaking change in 4.46.1

https://github.com/vue-styleguidist/vue-styleguidist/releases/tag/vue-styleguidist%404.46.0

@elevatebart
Copy link
Member

I will close this issue now, please open separate issues for bug reports ;)

TYTYTY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request intend to implement Sometime in the next 2 major release this will be implemented
Projects
Development

No branches or pull requests