iis服务器助手广告广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >关于vite.config.ts文件的配置方式
  • 159
分享到

关于vite.config.ts文件的配置方式

2024-04-02 19:04:59 159人浏览 独家记忆
摘要

目录vite.config.ts文件的配置1、alias配置别名2、关于path的引入vite项目在jenkins自动打包报错2种解决方案vite.config.ts文件的配置 im

vite.config.ts文件的配置

import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],  // 注册插件
  server: {
    open: true
  },
  resolve: {
    alias: {
      // 如果报错__dirname找不到,需要安装node,执行yarn add @types/node --save-dev
      "@": path.resolve(__dirname, "src"),
      "comps": path.resolve(__dirname, "src/components"),
    }
  }
})

1、alias配置别名

如果报错__dirname找不到,需要安装node,

执行yarn add @types/node --save-dev

2、关于path的引入

不要再使用 let path = require(‘path’)

使用 import path from ‘path’ 进行引入

vite项目在jenkins自动打包报错

failed to load config from ../vite.config.js You installed esbuild on

vite项目在jenkins自动打包报错找不到esbuild-linux-64

在window环境开发用的找不到esbuild-windows-64,在linux环境构建需要使用esbuild-linux-64,找不到esbuild-linux-64就会报错

实际报错:

error during build:
11:21:11 Error: 
11:21:11 You installed esbuild on another platfORM than the one you're currently using.
11:21:11 This won't work because esbuild is written with native code and needs to
11:21:11 install a platform-specific binary executable.
11:21:11 
11:21:11 Specifically the "esbuild-windows-64" package is present but this platform
11:21:11 needs the "esbuild-linux-64" package instead. People often get into this
11:21:11 situation by installing esbuild on Windows or MacOS and copying "node_modules"
11:21:11 into a Docker image that runs Linux, or by copying "node_modules" between
11:21:11 Windows and WSL environments.

报错原因: vite在linux环境打找不到esbuild-linux-64

2种解决方案

1、在linux环境下,打包前先 npm i esbuild-linux-64

2、在外网windows环境下运行以下命令(可在版本号去package-lock.JSON中查看esbuild-linux-64版本号后自行修改下载)

curl -O Https://reGIStry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.34.tgz

下载后解压得到package文件夹,将其改名为esbuild-linux-64复制到当前项目node_modules目录下即可

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: 关于vite.config.ts文件的配置方式

本文链接: https://www.lsjlt.com/news/165854.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作