-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
33 lines (26 loc) · 1.11 KB
/
index.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 path = require('path');
const markLoaderGlobal = (markName) => (
`; var __markLoaderGlobal = typeof global === 'object' ? global : window;`
);
const startMark = (markName) => (
`;__markLoaderGlobal.performance && __markLoaderGlobal.performance.mark && __markLoaderGlobal.performance.mark('${markName}_start'); `
);
const endMark = (markName) => (
`;__markLoaderGlobal.performance && __markLoaderGlobal.performance.mark && __markLoaderGlobal.performance.mark('${markName}_end'); `
);
const measure = (markName) => (
`;__markLoaderGlobal.performance && __markLoaderGlobal.performance.measure && __markLoaderGlobal.performance.measure('${markName}', '${markName}_start', '${markName}_end'); `
);
const markLoader = function markLoader(content) {
const context = this._compiler && this._compiler.context || process.cwd() || '';
const resourcePath = this.resourcePath;
const markName = path.relative(context, resourcePath).replace(/[^a-zA-Z0-9]/g, '_');
return [
markLoaderGlobal(),
startMark(markName),
content,
endMark(markName),
measure(markName),
].join('');
};
module.exports = markLoader;