/
RawPackager.js
37 lines (29 loc) 路 967 Bytes
/
RawPackager.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
const Packager = require('./Packager');
const path = require('path');
const fs = require('@parcel/fs');
class RawPackager extends Packager {
static shouldAddAsset() {
// We cannot combine multiple raw assets together - they should be written as separate bundles.
return false;
}
// Override so we don't create a file for this bundle.
// Each asset will be emitted as a separate file instead.
setup() {}
async addAsset(asset) {
let contents = asset.generated[this.bundle.type];
if (!contents || (contents && contents.path)) {
contents = await fs.readFile(contents ? contents.path : asset.name);
}
// Create sub-directories if needed
if (this.bundle.name.includes(path.sep)) {
await fs.mkdirp(path.dirname(this.bundle.name));
}
this.size = contents.length;
await fs.writeFile(this.bundle.name, contents);
}
getSize() {
return this.size || 0;
}
end() {}
}
module.exports = RawPackager;