import webpack from 'webpack' ; import babelLoader from 'babel-loader' ; const macrosRegex = /[./]macro(\.c?js)?['"]/ ; const testMacrosRegex = v => macrosRegex . test ( v ) ; /**
 * this loader is designed to for these reasons:
 * 1. only load `babel-loader` and `babel-plugin-macros` if source code contains a macro dependency
 * 2. disable Webpack cache to trigger macro compilation on every build
 */ const FixBabelLoaderForMacro = function FixBabelLoaderForMacro ( source , inputSourceMap ) { if ( testMacrosRegex ( source . toString ( ) ) ) { if ( this . cacheable ) { this . cacheable ( false ) ; } babelLoader . call ( this , source , inputSourceMap ) ; return ; } const callback = this . async ( ) ; callback ! ( null , source ) ; } ; module . exports = FixBabelLoaderForMacro ;