My project is written in TypeScript and uses webpack to bundle scripts. All .ts files go through the TypeScript loader in order to transpile them to JavaScript; what I am trying to figure out how to do is to have some some specific imports go through a custom webpack loader. Something like:
import widget from 'myCustomLoader!./widget';
Of course, this doesn't work because TypeScript has no idea how to interpret webpack's loader syntax. Ideally TypeScript would just ignore everything before the ! and just look at './widget' for the purposes of type checking.
Another possibility I considered is to have all .ts files go through myCustomLoader by specifying it in webpack.config, and then using some sort of querystring to signal it to do it's work. For example:
import widget from './widget?myCustomLoader=true';
But TypeScript still can't handle that. Obviously using require directly will work:
var widget = require('myCustomLoader!./widget');
...but then I've lost all the type safety that TypeScript offers. Can anyone suggest a way to specify (or otherwise interact with) a custom webpack loader and still keep the type safety benefits of TypeScript import syntax?