Skip to content

Commit 2c49770

Browse files
authored
Use resolve.alias instead of custom resolver for @mwdb-web (#822)
1 parent 10c870b commit 2c49770

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

mwdb/web/vite.config.ts

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import react from "@vitejs/plugin-react";
33
import checker from "vite-plugin-checker";
44

55
import fs from "fs";
6-
import { join } from "path";
6+
import { join, resolve } from "path";
77

88
function findInstalledPlugins(namespace) {
99
const modulesDir = join(__dirname, "node_modules", namespace);
@@ -47,46 +47,28 @@ function pluginLoader() {
4747
};
4848
}
4949

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-
8150
export default defineConfig({
8251
plugins: [
8352
react(),
8453
pluginLoader(),
85-
pluginExposeCommons(),
8654
checker({
8755
typescript: true,
8856
}),
8957
],
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: /^@mwdb-web(?!\/(plugins$|plugin-))/,
68+
replacement: resolve(__dirname, "./src")
69+
}
70+
]
71+
},
9072
server: {
9173
host: "0.0.0.0",
9274
port: 3000,

0 commit comments

Comments
 (0)