I have a project that is using SystemJS - this cannot change. We are also using StoryBooks, which uses WebPack - this too cannot change. So far the two play very nicely with each other. However, I have a module which loads files as plain text and parses them:
import stuff from './some-module!systemjs-plugin-text';
parseStuff(stuff);
If my project were using WebPack, the above code would look like this:
import stuff from 'raw-loader!./some-module';
parseStuff(stuff);
Since SystemJS is the "primary" module loader, I want all application code to stay SystemJS-centric. I would like to write a custom resolver for webpack to take the SystemJS-style imports and "flip" them (so to speak). The code would look like this:
const moduleMap = {
'systemjs-plugin-text': 'raw-loader'
};
const formatModuleIdForWebPack (systemjsId) {
const webpackId = systemjsId.split('!').reverse();
webpackId[0] = moduleMap[ webpackId[0] ] || webpackId[0];
return webpackId.join('!');
}
formatModuleIdForWebPack('./some-module!systemjs-plugin-text');
//-> 'raw-loader!./some-module'
I have followed several examples for creating a custom resolver (here and here), but none of the payloads contain all of the data I need to reconstruct the request object. Is there a way can I hook into WebPack very early in the module parsing to achieve my goal?