I would like to use the code separation feature provided by webpack to create several typescript packages of my application and download them on demand. I have been looking for a solution on the line for a while, and the closest answer I found is the following:
https://github.com/TypeStrong/ts-loader/blob/master/test/execution-tests/babel-codeSplitting/require.d. ts
This example is directly taken from the official ts-loader documentation and shows how to rely on require.ensure to create a split point.
The thing that bothers me is that in typescript there is no easy way to do this. The require.ensure function must be called directly in typescript. The following declaration file must be provided to allow typescript to silently digest this call:
declare var require: {
<T>(path: string): T;
(paths: string[], callback: (...modules: any[]) => void): void;
ensure: (paths: string[], callback: (require: <T>(path: string) => T) => void) => void;
};
Is there a more elegant way to achieve the same result?
source
share