This template should help get you started developing with Vue 3 in Vite.
VSCode + Volar (and disable Vetur) + TypeScript Vue Plugin (Volar).
TypeScript cannot handle type information for .vue imports by default, so we replace the tsc CLI with vue-tsc for type checking. In editors, we need TypeScript Vue Plugin (Volar) to make the TypeScript language service aware of .vue types.
If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a Take Over Mode that is more performant. You can enable it by the following steps:
- Disable the built-in TypeScript Extension
- Run
Extensions: Show Built-in Extensionsfrom VSCode's command palette - Find
TypeScript and JavaScript Language Features, right click and selectDisable (Workspace)
- Run
- Reload the VSCode window by running
Developer: Reload Windowfrom the command palette.
See Vite Configuration Reference.
npm installnpm run devnpm run buildLint with ESLint
npm run lint
-
分包
1、 将下面添加至vite.config.ts 文件中 const multiPage: any = {} const pageEntry: any = {} function getInput() { const allEntry = glob.sync('./src/packages/**/index.html') allEntry.forEach((entry: string) => { const pathArr = entry.split('/') const name = pathArr[pathArr.length - 2] multiPage[name] = { name, rootPage: `/src/packages/${name}/index.html` } pageEntry[name] = resolve(__dirname, `/src/packages/${name}/index.html`) }) } function pathRewritePlugin() { const rules: any[] = [] Reflect.ownKeys(multiPage).forEach((key) => { rules.push({ from: `/${multiPage[key].name}`, to: `${multiPage[key].rootPage}` }) }) return { name: 'path-rewrite-plugin', configureServer(server: any) { server.middlewares.use( history({ htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'], disableDotRule: undefined, rewrites: rules }) ) } } } getInput() 2、 添加路由重写插件 plugins: [pathRewritePlugin()]` -
chrome 低版本兼容
1、import legacy from '@vitejs/plugin-legacy' 2、plugins 添加插件 // 浏览器兼容 legacy({ targets: ['defaults', 'not IE 11', 'chrome 49', 'maintained node versions'], additionalLegacyPolyfills: ['regenerator-runtime/runtime'] }) 3、build 构建中设置最终构建的浏览器兼容目标 target: ['chrome 49'],