今天使用 vite 和 vue-cli。
out-of-the-box for vue-cli projects without any codebase modifications.
demo/boilerplate
# 1. first step
vue add vite
# 2. second step
# NOTE you cannot directly use `vite` or `npx vite` since it is origin vite not this plugin.
yarn vite // or npm run vite
# 3. add optimizeDeps#include (optional and will speedup devServer start time a lot)
# added in vue.config.js#pluginOptions.vite.optimizeDeps.include
# e.g.: ['vue', 'vue-router', 'vuex']
# all scanned deps(logged in terminal) can be added for speedup.…vue-cli-plugin-vitepackage.json#scripts#vite and one file at bin/vitevue.config.js (publicPath, alias, outputDir...)| Dimension | vue-cli | vite |
|---|---|---|
| Plugin | 1. based on webpack. | |
| 2. have service and generator lifecycles. | ||
| 3. hooks based on each webpack plugin hooks | 1. based on rollup. | |
| 2. no generator lifecycle. | ||
| 3. universal hooks based on rollup plugin hooks and vite self designed | ||
| Environment Variables | 1. loaded on process.env. | |
2. prefixed by VUE_APP_. |
||
3. client-side use process.env.VUE_APP_XXX by webpack definePlugin |
1. not loaded on process.env. | |
2. prefixed by VITE_. |
||
3. client-side use import.meta.env.VITE_XXX by vite inner define plugin |
||
| Entry Files | 1. main.{js,ts}. | 1. *.html |
| Config File | 1. vue.config.js | 1. vite.config.ts. |
| 2. support use --config to locate | ||
| MPA Support | 1. native support by options.pages. |
|
| 2. with history rewrite support | 1. native support by rollupOptions.input |
|
| Special Syntax | 1. require(by webpack) | |
| 2. require.context(by webpack) | ||
2. use ~some-module/dist/index.css(by css-loader) |
||
| 3. module.hot for HMR | 1. import.meta.glob/globEager | |
2. native support by vite, use module/dist/index.css directly |
||
| 3. import.meta.hot for HMR | ||
| Local devServer | 1. webpack dev-server | |
| 2. express-style middleware and many extension api. | 1. connect | |
| 2. connect middleware | ||
| Type Checker | 1. fork-ts-checker-webpack-plugin | 1. No built-in, we can use vite-plugin-checker(based on vetur and vue-tsc) |
| Lint | 1. @vue/cli-plugin-eslint | 1. No built-in we can use vite-plugin-eslint, |
| Jest | 1. @vue/cli-plugin-jest | 1. will have first-class jest support |
VUE_APP_ prefixprocess.env.${PREFIX}_XXX for client-sideprocess.env.PUBLIC_URL || vue.config.js#publicPath || baseUrlcsscss.loaderOptionsdevServerprocess.env.DEV_HOST || devServer.publicNumber(process.env.PORT) || devServer.portdevServer.httpsprocess.platform === 'darwin' || devServer.opendevServer.proxyoutputDircss.extractprocess.env.GENERATE_SOURCEMAP === 'true' || productionSourceMap || css.sourceMapvue.config.js#runtimeCompileryou can clone/fork this repo, under examples/*
require('xxx')module.xxx暂无开放 Issues,或尚未同步最近议题。