I need to be able to replace a fairly large module in my Angular app with a very simple one in order to make my Server Side Rendering build load (avoiding all the unnecessary requires for a component that's too rich to work on the server anyway). Without the replacement the code is trying to load window
or document
. Some libraries I was able to replace simply with a null-loader
but in this instance I need cut off an entire dependency tree by trimming this one specific Angular module.
Despite all my attempt to override the original module, Angular (@ngtools/webpack
) still somehow succeeds in generating require
calls for the components I was hoping to trim ...
I tried:
- Using
hostReplacementPaths
parameter to the compiler plugin
new AngularCompilerPlugin({
tsConfigPath: 'tsconfig.ssr.json',
entryModule: path.join(__dirname, 'src/js/landing/landing.server.module.ts#LandingServerModule'),
hostReplacementPaths: {
[path.resolve('./src/js/app/help.module.ts')]: path.resolve('./src/js/landing/server-mock.module.ts')
}
})
- Using
NormalModuleReplacementPlugin
new NormalModuleReplacementPlugin(
/help\.module\./,
resource => {
resource.requestresource.request.replace('app/help.module.ts', 'landing/server-mock.module.ts')
},
),
file-replace-loader
{
test: /help\.module\.ts/,
loader: 'file-replace-loader',
options: {
condition: 'if-replacement-exists',
replacement: path.resolve('./src/js/landing/server-mock.module.ts'),
async: true,
}
},
I suspect the angular compiler is scanning the files for dependencies outside of webpack ...
Any ideas how I could override a single Angular module with a mock module at build time?