vite.config.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* eslint-disable */
  2. import legacyPlugin from '@vitejs/plugin-legacy';
  3. // import usePluginImport from 'vite-plugin-importer';
  4. import * as path from 'path';
  5. import vuePlugin from '@vitejs/plugin-vue';
  6. // @see https://cn.vitejs.dev/config/
  7. export default ({
  8. command,
  9. mode
  10. }) => {
  11. let rollupOptions = {};
  12. let optimizeDeps = {};
  13. let alias = {
  14. '@': path.resolve(__dirname, './src'),
  15. 'vue$': 'vue/dist/vue.runtime.esm-bundler.js',
  16. }
  17. let proxy = {
  18. 'undefined': {
  19. "target": "undefined:undefined/",
  20. "changeOrigin": true,
  21. "pathRewrite": {
  22. "^undefined": ""
  23. }
  24. },
  25. }
  26. let define = {
  27. 'process.env.NODE_ENV': '"development"',
  28. }
  29. let esbuild = {}
  30. return {
  31. base: './', // index.html文件所在位置
  32. root: './', // js导入的资源路径,src
  33. resolve: {
  34. alias,
  35. },
  36. define: define,
  37. server: {
  38. // 代理
  39. proxy,
  40. },
  41. build: {
  42. target: 'es2015',
  43. minify: 'terser', // 是否进行压缩,boolean | 'terser' | 'esbuild',默认使用terser
  44. manifest: false, // 是否产出maifest.json
  45. sourcemap: false, // 是否产出soucemap.json
  46. outDir: 'build', // 产出目录
  47. rollupOptions,
  48. },
  49. esbuild,
  50. optimizeDeps,
  51. plugins: [
  52. legacyPlugin({
  53. targets: ['Android > 39', 'Chrome >= 60', 'Safari >= 10.1', 'iOS >= 10.3', 'Firefox >= 54', 'Edge >= 15'],
  54. }), vuePlugin(),
  55. ],
  56. css: {
  57. preprocessorOptions: {
  58. less: {
  59. // 支持内联 JavaScript
  60. javascriptEnabled: true,
  61. }
  62. }
  63. },
  64. }
  65. }