/
_config.js
55 lines (54 loc) · 1.3 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const assert = require('assert');
const path = require('path');
const sideEffects = [];
module.exports = {
description: 'supports setting module side effects to false for external modules',
context: {
require(id) {
sideEffects.push(id);
return { value: id };
},
sideEffects
},
exports() {
assert.deepStrictEqual(sideEffects, ['pluginsideeffects-true', 'internal']);
},
options: {
treeshake: {
moduleSideEffects: 'no-external'
},
plugins: {
name: 'test-plugin',
resolveId(id) {
if (!path.isAbsolute(id)) {
if (id === 'internal') {
return id;
}
if (id === 'implicit-external') {
return null;
}
const moduleSideEffects = JSON.parse(id.split('-')[1]);
if (moduleSideEffects) {
return { id, moduleSideEffects, external: true };
}
return { id, external: true };
}
},
load(id) {
if (!path.isAbsolute(id)) {
return `export const value = '${id}'; sideEffects.push(value);`;
}
}
}
},
warnings: [
{
code: 'UNRESOLVED_IMPORT',
importer: 'main.js',
message:
"'implicit-external' is imported by main.js, but could not be resolved – treating it as an external dependency",
source: 'implicit-external',
url: 'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency'
}
]
};