forked from observablehq/plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
36 lines (34 loc) · 1.24 KB
/
vite.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import path from "path";
import {defineConfig} from "vite";
import glob from "glob";
// Vite will automatically try to resolve to .ts files when an imported .js file
// doesn't exist, but only if the importer is .ts. In order to fall back on .ts
// for all.js imports that don't exist, we provide a customResolver below that
// will do this based on the js and ts files we have in src/. Once all of the
// files in src/ are converted to TypeScript we can remove this customLoader.
const typescriptPaths = new Set(glob.sync(`${path.resolve("./src")}/**/*.ts`));
const javascriptPaths = new Set(glob.sync(`${path.resolve("./src")}/**/*.js`));
export default defineConfig({
root: "./test/plots",
publicDir: path.resolve("./test"),
resolve: {
alias: [
{find: "@observablehq/plot", replacement: path.resolve("./src/index.js")},
{
find: /^(.*)\.js$/,
replacement: "$1",
customResolver: (importee, importer) => {
const base = path.join(path.dirname(importer), importee);
const js = `${base}.js`;
const ts = `${base}.ts`;
if (javascriptPaths.has(js)) return js;
if (typescriptPaths.has(ts)) return ts;
}
}
]
},
server: {
port: 8008,
open: "/"
}
});