vuepress / core

Vue-Powered Static Site Generator
https://vuepress.vuejs.org
MIT License
2.29k stars 926 forks source link

Some questions and suggestions #11

Closed Mister-Hope closed 3 years ago

Mister-Hope commented 3 years ago

Questions:

  1. Is there a way to access themeConfig in plugin options?

    We used to access it through context, but it is now replaced by app provided by vue3. And current plugins are not accessing it, so I am not sure how to access it or whether I can access it in vuepress2

Improvements suggestions:

  1. We can use script link to link script part and compile it to js. Both vitepress and my theme is doing this way. It can help to speed up the serve and build time. So I would like to suggest removing the runtime typescript for the default theme. Also this can let the users drop the typescript deps, while they can still use this along with typescript.

    image

  2. Due to the new useApi, some plugins may wanna provide some useApi funtions or wanna export some types(e.g.: vuepress-plugin-blog has to do so), but with the common js design, we can only use export = in typescript and it's a bit inconvinient for us to hang those functions on this plugin object:

    const options = (options: XXXOptions) => xxx;
    
    options.useXXX = useXXX;
    
    export = options;

    And also we have to write the declaration files intead of generating them. in order to provide type export.

    So can we both support plugin exporting a funtion and a object with a setup(or something like install)? Just like what vue is doing. It would be better for developers to export other types and funtions.

    Also this can be a new breaking change because when the plugin is exporting an object, it should also use:

    module.exports = () =>({
      ...
    });

    https://v3.vuejs.org/api/application-api.html#use

    By the way, the mixed es module and common js can be really annoying when using typescript, especially you want to require one file in both es module and commonjs files.


Also, I am preparing the Postgraduate Exam on Dec 26th, but I would like to help with the pwa plugins and seo plugins for vuepress2, so if you can wait till Dec 31th, I can help with them after my exam.

These are my plugins, and they are both powerful than @vuepress/plugin-pwa and vuepress-plugin-seo, and I can make them compatable with vuepress2 and make some improvements with the new feature:

And since we can inject script and links in head, so it can be more powerful in vuepress2.

I think seo is important for documentations and blog sites, so in my opinion, it would be better maitained by the official.

meteorlxy commented 3 years ago

Question 1

app.options.themeConfig

But it's not suggested to access themeConfig in plugins, a plugin should only consider it's own options. It should be theme's business to handle themeConfig and set corresponding plugin config.

Suggestion 1

Vitepress has migrated to <script setup>.

Pre-compile the standalone .ts files is a optimization, but a more complete solution cloud be pre-compiling the .vue files with rollup.

However, we currently don't implement it because the pallete support (pallete.styl and index.styl) and the default theme ejection (vuepress eject in vuepress 1, not impelemented in v2 yet).

In addition, typescript is not required as a dependency, because we have migrated to use esbuild-loader.

Suggestion 2

We have supported both module.exports and export default in plugins, so this should not be a problem anymore. You can check out our current plugins.

As for the mix of esm and cjs, yes it is annoying indeed, and that might be one of the reasons that vitepress is not going to support node-side plugins. Our current solution is to create tsconfig.cjs.json and tsconfig.esm.json to handle them.

(Hope the native esm support of nodejs can be enabled universally)

PWA and SEO plugins

I think I would migrate v1 PWA plugin first. Of course contributions are welcome.


Take your exam top priority. OSS is not so important lol.

I'll close this first. Feel free to comment if you have any further ideas