-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.ts
53 lines (44 loc) · 1.57 KB
/
index.ts
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
52
53
import * as Loader from './src/Loader';
import * as options from './src/options';
import { BUILT_IN_CODEGENS } from './src/builtin_codegens';
function loader(source, sourcemap) {
this.cacheable && this.cacheable();
this.async();
const l = new Loader.Loader(this);
l.replace(source)
.then( results => {
if (results) {
results.forEach( result => {
source = result.source;
if (result.debug) {
const d = [
'================================== ng-router-loader ==================================',
`Importer: ${this.resourcePath}`,
`Raw Request: ${result.match}`,
`Replacement: ${result.replacement}`,
'======================================================================================'
];
console.log(d.join('\n'));
}
});
}
this.callback(null, source, sourcemap);
})
.catch( err => this.callback(err) );
}
module loader {
export type ReplaceResult = Loader.ReplaceResult;
export type LoaderCodeGen = Loader.LoaderCodeGen;
export type RouterLoaderOptions = options.RouterLoaderOptions;
export type RouteResourceOptions = options.RouteResourceOptions;
/**
* Add a code generator that can be used in the 'loader' option.
* @param name
* @param codeGen
*/
export function setCodeGen(name: string, codeGen: Loader.LoaderCodeGen) {
Loader.Loader.setCodeGen(name, codeGen);
}
}
BUILT_IN_CODEGENS.forEach( (cgDef) => Loader.Loader.setCodeGen(cgDef.name, cgDef.codeGen) );
export = loader;