请教一个vite打包的问题,我用springboot3+vue3+vite5做了一个项目,本地运行正常,但打包时遇到了问题。即打包后,dist文件夹中只有几个文件,不知是否正常?另外,出现了下面问题,不知是什么原因?
打包放到服务器上后,首页(登录页面)可以访问,但输入用户名和密码后点击登录,出现下面错误:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
TypeError: Failed to fetch dynamically imported module: http://localhost/views/index.vue
TypeError: Failed to fetch dynamically imported module: http://localhost/views/index.vue
打包方式一:打包命令运行结果如下
> vite build
vite v5.3.5 building for production...
✓ 1571 modules transformed.
dist/index.html 0.48 kB │ gzip: 0.32 kB
dist/assets/bgimg-DjLelNA2.jpeg 7,784.52 kB
dist/assets/index-Dw9PIufV.css 324.93 kB │ gzip: 44.90 kB
dist/assets/index-BGWgzp1d.js 628.88 kB │ gzip: 213.56 kB
(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 3.77s
打包方式二:我在vite.config.js中加上下面配置:
build: {
chunkSizeWarningLimit: 1000,
rollupOptions: {
output: {
// 分包
manualChunks(id) {
if (id.includes("node_modules")) {
return id
.toString()
.split("node_modules/")[1]
.split("/")[0]
.toString();
}
},
},
},
}
这次打包出的文件多了一些,打包命令运行结果如下:
> vite build
vite v5.3.5 building for production...
✓ 1571 modules transformed.
Generated an empty chunk: "@floating-ui".
Generated an empty chunk: "dayjs".
Generated an empty chunk: "lodash-unified".
Generated an empty chunk: "memoize-one".
Generated an empty chunk: "normalize-wheel-es".
Generated an empty chunk: "vue".
dist/index.html 1.54 kB │ gzip: 0.54 kB
dist/assets/bgimg-DjLelNA2.jpeg 7,784.52 kB
dist/assets/index-_rFj-IOj.css 1.60 kB │ gzip: 0.51 kB
dist/assets/element-plus-BJZDLfJd.css 323.34 kB │ gzip: 44.55 kB
dist/assets/dayjs-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/assets/vue-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/assets/@floating-ui-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/assets/normalize-wheel-es-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/assets/lodash-unified-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/assets/memoize-one-l0sNRNKZ.js 0.00 kB │ gzip: 0.02 kB
dist/assets/pinia-plugin-persistedstate-RV7uh3T-.js 1.94 kB │ gzip: 0.90 kB
dist/assets/pinia-CXYsz0yr.js 3.84 kB │ gzip: 1.97 kB
dist/assets/@vueuse-DFh7vuZN.js 6.08 kB │ gzip: 2.64 kB
dist/assets/@ctrl-r5W6hzzQ.js 14.13 kB │ gzip: 4.76 kB
dist/assets/async-validator-DKvM95Vc.js 16.90 kB │ gzip: 5.41 kB
dist/assets/@popperjs-D9SI2xQl.js 19.77 kB │ gzip: 7.37 kB
dist/assets/lodash-es-CbX0-HeL.js 22.01 kB │ gzip: 7.80 kB
dist/assets/vue-router-DyUJW7uH.js 23.12 kB │ gzip: 9.48 kB
dist/assets/axios-DTyqpfTh.js 34.60 kB │ gzip: 13.93 kB
dist/assets/@vue-5jp81eLw.js 70.09 kB │ gzip: 27.98 kB
dist/assets/index-lL5Sh4cQ.js 104.57 kB │ gzip: 41.58 kB
dist/assets/element-plus-BKnJWsug.js 140.07 kB │ gzip: 47.39 kB
dist/assets/@element-plus-C7iXwfg3.js 172.90 kB │ gzip: 44.58 kB
✓ built in 3.70s