安装插件
// 一个vite必备,第二个是为了兼容vue2 npm i -D vite vite-plugin-vue2
将public中的index.html拉出来,放在最外层,与package.json同级
在index.html中引入main.js
<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <link rel="icon" href="/favicon.ico"> <title>vue2+vite</title> </head> <body> <div id="app"></div> <script type="module" src="/src/main.js"></script> </body> </html>
router中的index.js修改base
创建vite.config.js(没有则需要新建)
import { createVuePlugin } from "vite-plugin-vue2";import { defineConfig } from "vite";export default defineConfig({ server: { host: "192.168.10.107", }, // plugins: [createVuePlugin()], plugins: [ createVuePlugin({ vueTemplateOptions: {}, }), ], resolve: { extensions: [".vue", ".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"], alias: [ { find: "@", replacement: "/src", }, ], }, build: { // 设置vite打包大小控制 chunkSizeWarningLimit: 10000, }, });
修改package.json中的运行与打包命令
··· // 其他代码"scripts": { "serve": "vite --host", "build": "vite build" }, ··· // 其他代码
标签:index,js,json,build,vue2,使用,vite From: https://blog.51cto.com/u_16229496/7126307