/
_config.js
41 lines (41 loc) · 1.16 KB
/
_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
37
38
39
40
41
module.exports = {
solo: true,
description: 'handles pre-loading a cyclic module in the resolveId hook',
warnings: [
{
code: 'CIRCULAR_DEPENDENCY',
cycle: ['main.js', 'main.js?proxy', 'main.js'],
importer: 'main.js',
message: 'Circular dependency: main.js -> main.js?proxy -> main.js'
}
],
options: {
plugins: [
{
async resolveId(source, importer, options) {
if (!importer || importer.endsWith('?proxy')) {
return null;
}
console.log('resolve', source, importer);
const resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
console.log('resolution', resolution);
if (resolution && !resolution.external) {
const moduleInfo = await this.load(resolution);
if (moduleInfo.code.indexOf('/* use proxy */') >= 0) {
return `\0${resolution.id}?proxy`;
}
}
return resolution;
},
load(id) {
if (id.endsWith('?proxy')) {
const importee = id.slice(1, -'?proxy'.length);
console.log('load', JSON.stringify(id), importee);
return `export * from '${importee}'; export const extra = 'extra';`;
}
return null;
}
}
]
}
};