当前位置:   article > 正文

vue3-使用vite构建vue3+ts项目-设置路径别名@+打包后index.html白板问题_moduleresolution": "bundler", "allowimportingtsext

moduleresolution": "bundler", "allowimportingtsextensions": true, "resolvej

一、设置路径别名

1.在vite.config.ts文件defineConfig配置

  1. import { defineConfig } from 'vite';
  2. import vue from '@vitejs/plugin-vue';
  3. import { resolve } from 'path';
  4. // https://vitejs.dev/config/
  5. export default defineConfig({
  6. plugins: [vue()],
  7. resolve: {
  8. //设置路径别名
  9. alias: {
  10. '@': resolve(__dirname, './src'),
  11. '@P': resolve(__dirname, './src/page'),
  12. '*': resolve('')
  13. }
  14. },
  15. base: './'
  16. });

2.在tsconfig.json文件的compilerOptions配置baseUrl和paths

  1. {
  2. "compilerOptions": {
  3. "target": "ES2020",
  4. "useDefineForClassFields": true,
  5. "module": "ESNext",
  6. "lib": ["ES2020", "DOM", "DOM.Iterable"],
  7. "skipLibCheck": true,
  8. /* Bundler mode */
  9. "moduleResolution": "bundler",
  10. "allowImportingTsExtensions": true,
  11. "resolveJsonModule": true,
  12. "isolatedModules": true,
  13. "noEmit": true,
  14. "jsx": "preserve",
  15. /* Linting */
  16. "strict": true,
  17. "noUnusedLocals": true,
  18. "noUnusedParameters": true,
  19. "noFallthroughCasesInSwitch": true,
  20. "baseUrl": ".",
  21. "paths": {
  22. "@/*": ["src/*"],
  23. "@P/*": ["src/page/*"]
  24. }
  25. },
  26. "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
  27. "references": [{ "path": "./tsconfig.node.json" }]
  28. }

二、打包后index.html白板问题

在vite.config.ts文件defineConfig配置base: './'

  1. import { defineConfig } from 'vite';
  2. import vue from '@vitejs/plugin-vue';
  3. import { resolve } from 'path';
  4. // https://vitejs.dev/config/
  5. export default defineConfig({
  6. plugins: [vue()],
  7. resolve: {
  8. //设置路径别名
  9. alias: {
  10. '@': resolve(__dirname, './src'),
  11. '@P': resolve(__dirname, './src/page'),
  12. '*': resolve('')
  13. }
  14. },
  15. base: './'
  16. });

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/119681?site
推荐阅读
相关标签
  

闽ICP备14008679号