AOT +的WebPack + JSON动态需要

AOT +的WebPack + JSON动态需要

问题描述:

安装了的WebPack的AOT插件(https://www.npmjs.com/package/@ngtools/webpack)后,dynamic requires不再起作用:AOT +的WebPack + JSON动态需要

// Example that used to work 
public getJson<T>(fileName: String): T { 
    return require(`../../${fileName}_${this.lang}.json`); 
} 

随着标准ts-loaderawesome-typescript-loader等,dynamic requires工作,的WebPack捆绑json文件到主要app捆绑。但是,使用AoT/Webpack插件时,json文件根本就没有捆绑。我甚至觉得aot loader不再重复json文件。

任何想法如何让这个工作再次?谢谢。

信息:

https://github.com/angular/angular-cli/issues/3306

https://github.com/angular/angular-cli/pull/4153

更新:

作品有些与SystemJS -> System.import()但不稳定 https://github.com/angular/angular-cli/issues/6629#issuecomment-336411537

解决方法是使用System.import()建立负载和捆绑的动态文件,然后使用标准的WebPack机制加载的实际文件:

public getLazyFiles<T>(somePath: string): T { 
     /* AoT Hack - causes the AoT to find and prepare the dynamically loaded files */ 
     System.import(`../../${somePath}_${this.someSuffix}.json`); 
     /* ------- */ 
     // This is then used by webpack to actually load the files 
     return require(`../../${somePath}_${this.someSuffix}.json`); 
    } 

为什么需要这个解决办法在此说明:https://github.com/angular/angular-cli/issues/6629#issuecomment-336478854