-
Notifications
You must be signed in to change notification settings - Fork 4
/
compiler.js
51 lines (41 loc) · 1.5 KB
/
compiler.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
44
45
46
47
48
49
50
51
import { CachingCompiler } from 'meteor/caching-compiler';
import getOptions from './options';
let packageOptions;
export default class AssetsCompiler extends CachingCompiler {
constructor() {
super({
compilerName: 'static-assets',
defaultCacheSize: 1024 * 1024 * 10,
});
}
getCacheKey(inputFile) {
return `${packageOptions.hash}.${inputFile.getSourceHash()}`;
}
compileResultSize(compileResult) {
return compileResult.source.length;
}
processFilesForTarget(files) {
packageOptions = getOptions();
super.processFilesForTarget(files);
}
compileOneFile(inputFile) {
return { source: inputFile.getContentsAsBuffer(), };
}
addCompileResult(inputFile, compileResult) {
const packageRelativeHostingPath = `${packageOptions.pathPrefix}${inputFile.getPathInPackage()}`;
const appRelativeHostingPath = inputFile.getPackageName() ? `packages/${inputFile.getPackageName().replace(':', '_')}/${packageRelativeHostingPath}` : packageRelativeHostingPath;
let exportCode;
exportCode = packageOptions.exportAbsolutePaths
? `module.exports = require('meteor/meteor').Meteor.absoluteUrl('${appRelativeHostingPath}');`
: `module.exports = '${appRelativeHostingPath}';`;
inputFile.addJavaScript({
path: inputFile.getPathInPackage() + '.js',
sourcePath: inputFile.getPathInPackage(),
data: exportCode,
});
inputFile.addAsset({
data: inputFile.getContentsAsBuffer(),
path: `${packageRelativeHostingPath}`,
});
}
}