Debian Codegraph @

test/samples/transpile-concat-hires/build.js

raw
1 const MagicString = require('magic-string');
2 const { readFileSync, writeFileSync } = require('fs');
3
4 function load(filename) {
5 const contents = readFileSync(`${__dirname}/files/${filename}`, 'utf8');
6 return new MagicString(contents, { filename });
7 }
8 function save(filename, contents) {
9 writeFileSync(`${__dirname}/files/${filename}`, contents);
10 }
11
12 const main = load('main.js');
13 const placeholder = load('placeholder.js');
14
15 const search = '/* PLACEHOLDER */';
16 const index = main.original.indexOf(search);
17
18 const before = main.snip(0, index);
19 const after = main.snip(index + search.length, main.length());
20
21 const bundle = new MagicString.Bundle();
22 bundle.addSource(before);
23 bundle.addSource(placeholder);
24 bundle.addSource(after);
25
26 save('bundle.js', bundle.toString());
27 save('bundle.js.map', bundle.generateMap({
28 hires: true,
29 includeContent: true,
30 }).toString());