This repository was archived by the owner on Aug 7, 2021. It is now read-only.
File tree 5 files changed +40
-8
lines changed
5 files changed +40
-8
lines changed Original file line number Diff line number Diff line change 100
100
},
101
101
"devDependencies" : {
102
102
"@ngtools/webpack" : " ~7.2.0" ,
103
+ "@angular/compiler" : " ~7.2.0" ,
104
+ "@angular/compiler-cli" : " ~7.2.0" ,
103
105
"@types/jasmine" : " ^3.3.7" ,
104
106
"@types/node" : " ^10.12.12" ,
105
107
"@types/proxyquire" : " 1.3.28" ,
Original file line number Diff line number Diff line change
1
+ import { parse , sep } from "path" ;
2
+ import { AngularCompilerPlugin } from "@ngtools/webpack" ;
3
+
4
+ export function getAngularCompilerPlugin ( platform : string ) : any {
5
+ class NativeScriptAngularCompilerPlugin extends AngularCompilerPlugin {
6
+ // This is the bridge between the @ngtols /webpack loader and the AngularCompilerPlugin plugin itself:
7
+ // https://github.com/angular/angular-cli/blob/bf52b26219ffc16bed2dd55716e21773b415fd2a/packages/ngtools/webpack/src/loader.ts#L49
8
+ // The problem is that the loader does not call the `hostReplacementPaths` method when asking for the compiledFile.
9
+ // By overriding this method, we workaround this issue and support platform specific files from the loader
10
+ // that are not compiled by the AngularCompilerPlugin plugin. e.g. main.ts is the webpack entry point and
11
+ // it's loaded by the @ngtools/webpack loader but its not compiled by the plugin because the TypeScript Compiler
12
+ // knowns only about main.android.ts and main.ios.ts (main.ts is not imported/required anywhere in the app).
13
+ getCompiledFile ( file ) {
14
+ try {
15
+ if ( platform ) {
16
+ const parsed = parse ( file ) ;
17
+ const platformFile = parsed . dir + sep + parsed . name + "." + platform + parsed . ext ;
18
+ return super . getCompiledFile ( platformFile ) ; ;
19
+ }
20
+ }
21
+ catch ( e ) { }
22
+
23
+ return super . getCompiledFile ( file ) ;
24
+ }
25
+ }
26
+
27
+ return NativeScriptAngularCompilerPlugin ;
28
+ }
Original file line number Diff line number Diff line change @@ -3,5 +3,6 @@ module.exports = Object.assign({},
3
3
require ( "./NativeScriptSnapshotPlugin" ) ,
4
4
require ( "./PlatformSuffixPlugin" ) ,
5
5
require ( "./PlatformFSPlugin" ) ,
6
- require ( "./WatchStateLoggerPlugin" )
6
+ require ( "./WatchStateLoggerPlugin" ) ,
7
+ require ( "./NativeScriptAngularCompilerPlugin" )
7
8
) ;
Original file line number Diff line number Diff line change @@ -12,8 +12,7 @@ const CopyWebpackPlugin = require("copy-webpack-plugin");
12
12
const { BundleAnalyzerPlugin } = require ( "webpack-bundle-analyzer" ) ;
13
13
const { NativeScriptWorkerPlugin } = require ( "nativescript-worker-loader/NativeScriptWorkerPlugin" ) ;
14
14
const UglifyJsPlugin = require ( "uglifyjs-webpack-plugin" ) ;
15
- const { AngularCompilerPlugin } = require ( "@ngtools/webpack" ) ;
16
- const hashSalt = Date . now ( ) . toString ( ) ;
15
+ const hashSalt = Date . now ( ) . toString ( ) ;
17
16
18
17
module . exports = env => {
19
18
// Add your custom Activities, Services and other Android app components here.
@@ -27,6 +26,7 @@ module.exports = env => {
27
26
throw new Error ( "You need to provide a target platform!" ) ;
28
27
}
29
28
29
+ const AngularCompilerPlugin = nsWebpack . getAngularCompilerPlugin ( platform ) ;
30
30
const projectRoot = __dirname ;
31
31
32
32
// Default destination inside platforms/<platform>/...
@@ -261,10 +261,10 @@ module.exports = env => {
261
261
// configures the WebPack runtime to be generated inside the snapshot
262
262
// module and no `runtime.js` module exist.
263
263
( snapshot ? [ ] : [ "./runtime" ] )
264
- . concat ( [
265
- "./vendor" ,
266
- "./bundle" ,
267
- ] )
264
+ . concat ( [
265
+ "./vendor" ,
266
+ "./bundle" ,
267
+ ] )
268
268
) ,
269
269
// For instructions on how to set up workers with webpack
270
270
// check out https://github.com/nativescript/worker-loader
Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ const nativeScriptDevWebpack = {
22
22
getEntryModule : ( ) => 'EntryModule' ,
23
23
getResolver : ( ) => null ,
24
24
getEntryPathRegExp : ( ) => null ,
25
- getConvertedExternals : nsWebpackIndex . getConvertedExternals
25
+ getConvertedExternals : nsWebpackIndex . getConvertedExternals ,
26
+ getAngularCompilerPlugin : ( ) => AngularCompilerStub
26
27
} ;
27
28
28
29
const emptyObject = { } ;
You can’t perform that action at this time.
0 commit comments