Skip to content

Commit c000938

Browse files
committed
fix: fixed rollup resolve issues on build
added a new alias `@root` to be the root src folder
1 parent 7f90690 commit c000938

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

demo/src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createApp } from "vue";
22
import App from "./App.vue";
33

4-
import InfiniteLoading from "../../src/components/InfiniteLoading.vue";
4+
import InfiniteLoading from "@root/components/InfiniteLoading.vue";
55

66
const app = createApp(App);
77

demo/vite.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { defineConfig } from "vite";
22
import vue from "@vitejs/plugin-vue";
3+
import { fileURLToPath, URL } from "node:url";
34

45
// https://vitejs.dev/config/
56
export default defineConfig({
67
plugins: [vue()],
7-
alias: {
8-
"@parent/": require("path").resolve(__dirname, "../../"),
8+
resolve: {
9+
alias: {
10+
"@root": fileURLToPath(new URL("../src", import.meta.url)),
11+
"@": fileURLToPath(new URL("./src", import.meta.url)),
12+
},
913
},
1014
});

src/components/InfiniteLoading.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
2-
import type { Props, Params, State, StateHandler } from "../types";
2+
import type { Props, Params, State, StateHandler } from "@root/types";
33
import { onMounted, ref, toRefs, onUnmounted, watch, nextTick } from "vue";
4-
import { startObserver, getParentEl, isVisible } from "../utils";
4+
import { startObserver, getParentEl, isVisible } from "@root/utils";
55
// @ts-ignore
66
import Spinner from "./Spinner.vue";
77

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"declaration": true,
77
"outDir": "lib",
88
"declarationDir": "lib",
9-
"paths": { "@/*": ["./src/*"] },
9+
"paths": { "@root/*": ["./src/*"] },
1010
"baseUrl": "."
1111
}
1212
}

vite.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import path from "path";
1+
import { fileURLToPath, URL } from "node:url";
2+
import path from "node:path";
23
import { defineConfig } from "vite";
34
import vue from "@vitejs/plugin-vue";
45
import dts from "vite-plugin-dts";
@@ -28,4 +29,9 @@ export default defineConfig({
2829
formats: ["es", "umd"],
2930
},
3031
},
32+
resolve: {
33+
alias: {
34+
"@root": fileURLToPath(new URL("./src", import.meta.url)),
35+
},
36+
},
3137
});

0 commit comments

Comments
 (0)