-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
bundler.js
43 lines (37 loc) · 1.02 KB
/
bundler.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
import { merge } from "../utils.js";
// Default options
const defaults = {
extensions: [".ts", ".js"],
sourceMap: false,
options: {},
};
export default function (userOptions = {}) {
const options = merge(defaults, userOptions);
return (site) => {
site.loadAssets(options.extensions);
site.process(options.extensions, processor);
async function processor(file) {
const from = site.src(file.src.path + file.src.ext);
const { files } = await Deno.emit(from, {
...options,
sources: {
[from]: file.content,
},
});
for (const [path, content] of Object.entries(files)) {
if (path.endsWith(".js")) {
file.content = content;
file.dest.ext = ".js";
continue;
}
if (options.sourceMap && path.endsWith(".map")) {
const mapFile = file.duplicate();
mapFile.content = content;
mapFile.dest.ext = ".js.map";
site.pages.push(mapFile);
continue;
}
}
}
};
}