@@ -3,7 +3,7 @@ import react from "@vitejs/plugin-react";
3
3
import checker from "vite-plugin-checker" ;
4
4
5
5
import fs from "fs" ;
6
- import { join } from "path" ;
6
+ import { join , resolve } from "path" ;
7
7
8
8
function findInstalledPlugins ( namespace ) {
9
9
const modulesDir = join ( __dirname , "node_modules" , namespace ) ;
@@ -47,46 +47,28 @@ function pluginLoader() {
47
47
} ;
48
48
}
49
49
50
- function pluginExposeCommons ( ) {
51
- /**
52
- * Vite plugin that provides virtual module "@mwdb-web/commons/*".
53
- *
54
- * It maps src/commons modules to virtual package, so they're
55
- * available for plugins via simple import.
56
- */
57
-
58
- return {
59
- name : "expose-commons" ,
60
- resolveId ( id ) {
61
- if ( id . startsWith ( "@mwdb-web/commons/" ) ) {
62
- return "\0" + id ;
63
- }
64
- } ,
65
- load ( id ) {
66
- if ( id . startsWith ( "\0@mwdb-web/commons/" ) ) {
67
- const modulesPath = id . split ( "/" ) ;
68
- if ( modulesPath . length !== 3 ) {
69
- throw new Error (
70
- `Incorrect commons import '${ id } ', only one level deep allowed`
71
- ) ;
72
- }
73
- const submodule = modulesPath [ 2 ] ;
74
- const submodulePath = join ( __dirname , "src/commons" , submodule ) ;
75
- return `export * from "${ submodulePath } ";` ;
76
- }
77
- } ,
78
- } ;
79
- }
80
-
81
50
export default defineConfig ( {
82
51
plugins : [
83
52
react ( ) ,
84
53
pluginLoader ( ) ,
85
- pluginExposeCommons ( ) ,
86
54
checker ( {
87
55
typescript : true ,
88
56
} ) ,
89
57
] ,
58
+ /**
59
+ * Expose mwdb/web/src as @mwdb-web to make it
60
+ * reachable for plugins. The only thing that must
61
+ * be excluded from that aliasing is @mwdb-web/plugins
62
+ * that is virtual package provided by pluginLoader.
63
+ */
64
+ resolve : {
65
+ alias : [
66
+ {
67
+ find : / ^ @ m w d b - w e b (? ! \/ ( p l u g i n s $ | p l u g i n - ) ) / ,
68
+ replacement : resolve ( __dirname , "./src" )
69
+ }
70
+ ]
71
+ } ,
90
72
server : {
91
73
host : "0.0.0.0" ,
92
74
port : 3000 ,
0 commit comments