javascript - Code splitting with typescript and webpack -


i use code splitting feature provided webpack in order create several bundles of app, developed using typescript, , load them on demand. have been searching solution on line while , closest answer have found one: https://github.com/typestrong/ts-loader/blob/master/test/execution-tests/babel-codesplitting/require.d.ts

this example directly taken form official ts-loader documentation , shows how rely on require.ensure in order create split point.

the thing bugs me there no straightforward way in typescript that. require.ensure function must directly invoked in typescript. following declaration file needs provided allow typescript silently digest 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 more elegant way achieve same result?

is there more elegant way achieve same result

no. various runtimes have different (inconsistent) apis loading modules on demand. typescript choses agnostic here.

more

some notes on lazy loading , how works in terms of type safety : https://basarat.gitbooks.io/typescript/content/docs/project/external-modules.html


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -