Skip to content

Commit 0f4bd28

Browse files
fix: add plugin to fix aot relative path module errors
1 parent 304a028 commit 0f4bd28

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/commands/serve.ts

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { renderSassDir } from '../utilities/sass'
2424
import { exec, execSync } from 'child_process'
2525
import { NgSwPlugin } from '../fusebox/ng.sw.plugin'
2626
import { copy } from 'fs-extra'
27+
import { NgAotRelativePlugin } from '../fusebox/ng.aot-relative.plugin'
2728
import clearTerminal from '../utilities/clear'
2829
import readConfig_ from '../utilities/read-config'
2930

@@ -95,6 +96,11 @@ export function serve(
9596
useTypescriptCompiler: true,
9697
plugins: [
9798
isAotBuild && NgAotFactoryPlugin(),
99+
isAotBuild &&
100+
NgAotRelativePlugin({
101+
'"./not-found.component"': 'not-found/not-found.component',
102+
'"../response.service"': 'response/response.service'
103+
}),
98104
isServiceWorkerEnabled && NgSwPlugin(),
99105
Ng2TemplatePlugin(),
100106
['*.component.html', RawPlugin()],

src/fusebox/ng.aot-relative.plugin.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Plugin, File } from 'fuse-box'
2+
3+
// tslint:disable:no-class
4+
// tslint:disable:no-this
5+
// tslint:disable:no-if-statement
6+
// tslint:disable:no-object-mutation
7+
// tslint:disable:readonly-keyword
8+
export interface NgAotRelativePluginOptions {
9+
overwriteDict: Dict
10+
}
11+
12+
interface Dict {
13+
[key: string]: string
14+
}
15+
16+
function fromKeyValToSearchReplaceObject(obj: Dict) {
17+
return function(key: string) {
18+
return {
19+
search: new RegExp(key, 'g'),
20+
replace: `"fusing-angular-cli/.build/modules/src/modules/${obj[key]}"`
21+
}
22+
}
23+
}
24+
25+
export class NgAotRelativePluginClass implements Plugin {
26+
constructor(public opts: Dict = {}) {}
27+
28+
public test: RegExp = /.js/
29+
30+
onTypescriptTransform?(file: File) {
31+
Object.keys(this.opts)
32+
.map(fromKeyValToSearchReplaceObject(this.opts))
33+
.filter(a => a.search.test(file.contents))
34+
.forEach(a => {
35+
file.contents = file.contents.replace(a.search, a.replace)
36+
})
37+
}
38+
}
39+
40+
export const NgAotRelativePlugin = (dict?: Dict) =>
41+
new NgAotRelativePluginClass(dict)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, ChangeDetectionStrategy } from '@angular/core'
2-
// import { ResponseService } from '../response/browser'
2+
import { ResponseService } from '../response/browser'
33

44
// tslint:disable-next-line:no-class
55
@Component({
@@ -8,7 +8,7 @@ import { Component, ChangeDetectionStrategy } from '@angular/core'
88
changeDetection: ChangeDetectionStrategy.OnPush
99
})
1010
export class NotFoundComponent {
11-
// constructor(rs: ResponseService) {
12-
// rs.notFound()
13-
// }
11+
constructor(rs: ResponseService) {
12+
rs.notFound()
13+
}
1414
}

0 commit comments

Comments
 (0)