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

FAQ #9

Open
IndexXuan opened this issue Feb 24, 2021 · 1 comment
Open

FAQ #9

IndexXuan opened this issue Feb 24, 2021 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@IndexXuan
Copy link
Owner

Collect some FAQ here.

@IndexXuan IndexXuan added documentation Improvements or additions to documentation good first issue Good for newcomers labels Feb 24, 2021
@IndexXuan IndexXuan pinned this issue Mar 11, 2021
@IndexXuan
Copy link
Owner Author

IndexXuan commented Apr 13, 2021

Why vite so slow

  • It is because the first load of vite, it needs deps prebundle, you can use optimizeDeps for help.

How to debug this plugin

  • use VITE_DEBUG=true yarn vite, you will find something.

Vite Build Support

  • Currently only support vite dev for development, you should still use yarn build(vue-cli-service build)
  • But you can use BUILD=true MODERN=true yarn vite to invoke vite build(no legacy and use esbuild minify, not recommended, please use yarn build instead)

How to completely migrate to vite in the future

  • if this plugin help you fix error and use vite successfully, it is not too hard to migrate, compared to directly migrate from vue-cli or others
  • safely replace all VUE_APP_ to VITE_ code (e.g. .env.*)
  • safely replace all process.env.VUE_APP_ to import.meta.env.VITE_ in client-side code.
  • safely copy ./node_modules/vite-plugin-vue-cli/config/index.ts to $projectRoot/vite.config.ts and install corresponding vite-plugin list by it
  • add npm scripts dev: vite & build: vite build, remove other vue-cli scripts, like serve
  • migrate all require.context to import.meta.glob/globEager
  • remove all webpack plugins/vue-cli plugins and migrate all vue.config.js setted chainWebpack/configureWebpack to corresponding vite plugin or options
  • deps & devDeps cleanup
  • other cleanup and tests

Some module response 404 not found

  • if not compiler errors, maybe you import vue file without .vue ext, added it and it is required for vite and recommended for vue-cli (and required in vue-cli 5.x)

Custom Style missing fonts

/* theme color */
$--color-primary: teal;

/* icon font path, required */
$--font-path: '~element-plus/lib/theme-chalk/fonts'; // nothing to change

@import "~element-plus/packages/theme-chalk/src/index"; // nothing to change

JSX support

  • see options above, vitePluginVue2Options: { jsx: true }
  • you may also see that React is not defined, it is you use jsx without set vitePluginVue2Options: { jsx: true }

Vue 3 support

  • currently only support Vue2.x, since Vue3.x you can use vite directly
  • Vue 3 support by v1.0.0-rc.4

Deep reliance on Webpack(vue-cli-plugin)

  • for example: if project use lots of vue-cli-plugin to modify webpack-config, like vue-cli-plugin-auto-routing/vue-cli-plugin-mock/vue-cli-plugin-xxx, you should write vite-plugin-auto-routing/vite-plugin-mock/vite-plugin-xxx to do the same thing and pass in project vue.config.js#pluginOptions.vite.plugins.
// vue.config.js
import ViteAutoRouting from '@scope/vite-plugin-auto-routing'

module.exports = {
  pluginOptions: {
    vite: {
      plugins: [ViteAuthRouting()],
    },
  },
}

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

No branches or pull requests

1 participant