-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEjsAsset.js
33 lines (27 loc) · 812 Bytes
/
EjsAsset.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
const { Asset } = require('parcel-bundler');
const localRequire = require('parcel-bundler/lib/utils/localRequire');
class EjsAsset extends Asset {
constructor(name, options) {
super(name, options);
this.type = 'html';
this.hmrPageReload = true;
}
async generate() {
const ejs = await localRequire('ejs', this.name);
const config = (await this.getConfig(['.ejsrc', '.ejsrc.js', 'ejs.config.js'])) || {};
const compiled = ejs.compile(this.contents, {
compileDebug: false,
filename: this.name,
_with: false,
});
if (compiled.dependencies) {
for (let item of compiled.dependencies) {
this.addDependency(item, {
includedInParent: true,
});
}
}
return compiled(config.locals);
}
}
module.exports = EjsAsset;