I would like to use the code splitting feature provided by webpack in order to create several bundles of my app, developed using typescript, and load them on demand. I have been searching for a solution on line for a while and the closest answer I have found is this one: https://github.com/TypeStrong/ts-loader/blob/master/test/execution-tests/babel-codeSplitting/require.d.ts
This example is directly taken form the official ts-loader documentation and it shows how to rely on require.ensure in order to create a split point.
The thing that bugs me is that there is no a straightforward way in typescript to do that. The require.ensure function must be directly invoked in typescript. The following declaration file needs to be provided to allow typescript to silently digest that 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?