-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
vite.config.mjs
76 lines (70 loc) · 2.27 KB
/
vite.config.mjs
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* global process */
import { defineConfig } from 'vite';
import { babel } from '@rollup/plugin-babel';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';
import {
version,
resolvePackages,
exposedDependencies,
hiddenDependencies,
} from './rollup.config.mjs';
const require = createRequire(import.meta.url);
const projectRoot = dirname(fileURLToPath(import.meta.url));
const { packageName: getPackageName, PackageCache } = require('@embroider/shared-internals');
export default defineConfig(({ mode }) => {
process.env.EMBER_ENV = mode;
const build = {
rollupOptions: {
preserveEntrySignatures: 'strict',
output: {
preserveModules: true,
},
},
minify: mode === 'production',
};
return {
plugins: [
babel({
babelHelpers: 'bundled',
extensions: ['.js', '.ts'],
configFile: resolve(dirname(fileURLToPath(import.meta.url)), './babel.test.config.mjs'),
}),
resolvePackages({ ...exposedDependencies(), ...hiddenDependencies() }),
viteResolverBug(),
version(),
],
optimizeDeps: { noDiscovery: true },
publicDir: 'tests/public',
build,
};
});
function viteResolverBug() {
const packageCache = new PackageCache(projectRoot);
// https://github.com/vitejs/vite/issues/9731
return {
name: 'vite-resolver-bug',
resolveId(imported, importer) {
let packageName = getPackageName(imported);
if (packageName && importer) {
let owner = packageCache.ownerOfFile(importer);
if (owner?.name === packageName) {
// Our workaround for a vite bug also hits an actual node bug.🤡 You'd
// think we could pass `paths` to require.resolve in order to do the
// self-reference resolution ourselves, but you'd be wrong.
// https://github.com/nodejs/node/issues/47681
//
// So instead we have a very minimalist and incomplete implementation
// that's just good enough for the features we use
let hit = owner.packageJSON.exports?.['.' + imported.slice(packageName.length)];
if (hit) {
return {
id: resolve(owner.root, hit),
};
}
}
}
},
};
}