-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathrolldown.config.js
More file actions
69 lines (65 loc) · 1.5 KB
/
Copy pathrolldown.config.js
File metadata and controls
69 lines (65 loc) · 1.5 KB
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
/** @import { Plugin, RolldownOptions } from 'rolldown' */
import { builtinModules } from 'node:module';
import { rmSync } from 'node:fs';
import { join } from 'node:path';
/**
* @param {string} filepath
* @returns {Plugin}
*/
function clearOutput(filepath) {
return {
name: 'clear-output',
buildStart: {
order: 'pre',
sequential: true,
handler() {
rmSync(filepath, { recursive: true, force: true });
}
}
};
}
/**
* @returns {Plugin}
*/
function prefixBuiltinModules() {
return {
name: 'prefix-built-in-modules',
resolveId(source) {
if (builtinModules.includes(source)) {
return { id: 'node:' + source, external: true };
}
}
};
}
const dir_id = join(import.meta.dirname, 'src', 'dir.js');
/** @type {RolldownOptions} */
export default {
input: {
index: 'src/index.js',
handler: 'src/handler.js',
env: 'src/env.js'
},
output: {
dir: 'files',
format: 'esm',
hoistTransitiveImports: false,
chunkFileNames(chunk) {
if (chunk.name === 'dir') return '[name].js';
return 'chunks/[name].js';
},
codeSplitting: {
groups: [
{
name: 'dir',
test: dir_id
}
]
}
},
plugins: [clearOutput('files'), prefixBuiltinModules()],
// `MANIFEST` and `SERVER` are resolved at adapt time, and `@sveltejs/kit/node`
// is kept external so that it gets bundled _alongside_ the app's server code
// (rather than duplicated), see https://github.com/sveltejs/kit/issues/15755
external: ['MANIFEST', 'SERVER', '@sveltejs/kit/node'],
platform: 'node'
};