📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

vite-plugin-path-resolve

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-path-resolve

vite-plugin-path-resolve

1.0.1
latest
Source
npm
Version published
Weekly downloads
2
-94.74%
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-path-resolve

这个plugin主要是解决 vue2 + webpack 迁移至 vite 中的路径问题.

case1: src/demo1/index.vue
case2: src/demo2/index.js
case3: src/demo3.vue

这在webpack是没问题的, 但是vite的话就会报错. 因为这个路径找不到对应文件

Resolve

// ❌ in vite ,👌 in webpack
import demo1 from 'src/demo1'
import demo2 from 'src/demo2'
import demo3 from 'src/demo3'

to

// 🙆
import demo1 from 'src/demo1/index.vue'
import demo2 from 'src/demo2/index.js'
import demo3 from 'src/demo3.vue'

Usage

$ npm i vite-plugin-path-resolve -D
// vite.config.js
import pathResolve from 'vite-plugin-path-resolve'
function getPath(dir) {
    return path.resolve(path.dirname(fileURLToPath(import.meta.url)), dir)
}

export default defineConfig({
    plugins: [
        pathResolve({ src: getPath('src') }),
    ]
})

参数介绍

NameDescriptionDefault
Objectrequired 需要处理的绝对路径对象集合null
  • 传入这个对象, 这个plugin将会只处理这个路径集合下的文件

  • 请务必注意要绝对路径

FAQs

Package last updated on 24 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts