4 ms·
> I assume that if you integrate Babel and Webpack via webpack "loaders", some amount of work is saved (just guessing though) The Webpack babel-loader just cal
by dan15 7y ago
> I assume that if you integrate Babel and Webpack via webpack "loaders", some amount of work is saved (just guessing though)
The Webpack babel-loader just calls Babel with the source code, it doesn't reuse Webpack's AST: https://github.com/babel/babel-loader/blob/master/src/index.js#L204 https://github.com/babel/babel-loader/blob/master/src/index....
It has to do it that way, since Babel could parse some syntax that Webpack doesn't recognise (like Flow or TypeScript annotations). Webpack loaders can even take non-JS input and produce JS output (eg. "svgr" takes SVG images and produces React components) so I don't think Webpack can even assume that the input is JS at that point.
- _bxg1 7y agoAnd yet when it comes time for Webpack to crawl import statements, it can do so across all different kinds of files coming in through their own loaders. So I'm wondering if Webpack gets presented with some kind of structured "imports manifest" by the loaders, in which case I think it could skip its own parsing step.