vue2.7 + vue-router3 + pinia 示例代码: https://github.com/klren0312/vite_vue2.7 示例页面: https://klren0312.github.io/vite_vue2.7/
参考资料: https://github.com/vuejs/vetur/issues/2296#issuecomment-1155957974
需要在根目录创建vetur.config.js
// vetur.config.js
module.exports = {
settings: {
'vetur.completion.autoImport': false,
'vetur.experimental.templateInterpolationService': false,
'vetur.validation.interpolation': false,
'vetur.validation.template': false,
'vetur.validation.templateProps': false,
'vetur.validation.style': false,
'vetur.validation.script': false,
'vetur.format.enable': false,
'vetur.ignoreProjectWarning': true,
'vetur.languageFeatures.codeActions': false,
'vetur.languageFeatures.semanticTokens': false,
'vetur.languageFeatures.updateImportOnFileMove': false,
'vetur.trace.server': 'off',
'vetur.underline.refValue': false,
},
}
或者改用volar
插件
usevolar.png
参考资料: https://github.com/vuejs/vue/blob/main/CHANGELOG.md#vue-cli--webpack
vite创建vue项目后, 把插件替换下就行了
vue2应该只支持vue-router3版本
按官方文档引入即可: https://pinia.vuejs.org/getting-started.html#installation
import { createPinia, PiniaVuePlugin } from 'pinia'
Vue.use(PiniaVuePlugin)
const pinia = createPinia()
new Vue({
el: '#app',
// other options...
// ...
// note the same `pinia` instance can be used across multiple Vue apps on
// the same page
pinia,
})
使用方法(element-ui为例):
import Components from 'unplugin-vue-components/vite'
import { ElementUiResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
plugins: [
Components({
resolvers: [ElementUiResolver()],
}),
],
})
import legacy from '@vitejs/plugin-legacy'
export default defineConfig({
plugins: [
legacy({
targets: ['defaults', 'not ie < 9'],
}),
],
})
参考资料: https://cn.vitejs.dev/guide/build.html#chunking-strategy
import { splitVendorChunkPlugin } from 'vite'
export default defineConfig({
plugins: [
splitVendorChunkPlugin(),
],
build: {
rollupOptions: {
output: {
manualChunks: {
'element-ui': ['element-ui'],
},
},
},
},
})