src/loader.js
function tweakWebpackConfig(module) {
  const { default: webpackConfig = module } = module;

  const config = handleWebpackConfig(webpackConfig);

  if (!config) {
    throw new Error(
      'Not found webpack configuration. For multiple configurations in single file you must provide config with target "node".'
    );
  }

  const hmrClientEntry = require.resolve('./HmrClient');

  const addHmrClientEntry = (entry, entryOwner) => {
    const owner = entryOwner;
    if (Array.isArray(owner[entry])) {
      owner[entry].splice(-1, 0, hmrClientEntry);
    } else if (typeof owner[entry] === 'string') {
      owner[entry] = [hmrClientEntry, owner[entry]];
    } else if (typeof owner[entry] === 'function') {
      // Call function and try again with function result.
      owner[entry] = owner[entry]();
      addHmrClientEntry(entry, owner);
    } else if (typeof owner[entry] === 'object') {
      Object.getOwnPropertyNames(owner[entry]).forEach(name =>
        addHmrClientEntry(name, owner[entry])
      );
    }
  };

  // Add HmrClient to every entries.
  addHmrClientEntry('entry', config);

  if (!config.plugins) {
    config.plugins = [];
  }

  // Add source-map support if configured.
  if (config.devtool && config.devtool.indexOf('source-map') >= 0) {
    config.plugins.push(
      new webpack.BannerPlugin({
        banner: `;require('${require
          .resolve('source-map-support')
          .replace(/\\/g, '/')}').install();`,
        raw: true,
        entryOnly: false,
      })
    );
  }

  // Enable HMR globally if not.
  if (!config.plugins.find(p => p instanceof webpack.HotModuleReplacementPlugin)) {
    config.plugins.push(new webpack.HotModuleReplacementPlugin());
  }

  return config;
}
function tweakWebpackConfig(module) {
  const { default: webpackConfig = module } = module;

  const config = handleWebpackConfig(webpackConfig);

  if (!config) {
    throw new Error(
      'Not found webpack configuration. For multiple configurations in single file you must provide config with target "node".'
    );
  }

  const hmrClientEntry = require.resolve('./HmrClient');

  const addHmrClientEntry = (entry, entryOwner) => {
    const owner = entryOwner;
    if (Array.isArray(owner[entry])) {
      owner[entry].splice(-1, 0, hmrClientEntry);
    } else if (typeof owner[entry] === 'string') {
      owner[entry] = [hmrClientEntry, owner[entry]];
    } else if (typeof owner[entry] === 'function') {
      // Call function and try again with function result.
      owner[entry] = owner[entry]();
      addHmrClientEntry(entry, owner);
    } else if (typeof owner[entry] === 'object') {
      Object.getOwnPropertyNames(owner[entry]).forEach(name =>
        addHmrClientEntry(name, owner[entry])
      );
    }
  };

  // Add HmrClient to every entries.
  addHmrClientEntry('entry', config);

  if (!config.plugins) {
    config.plugins = [];
  }

  // Add source-map support if configured.
  if (config.devtool && config.devtool.indexOf('source-map') >= 0) {
    config.plugins.push(
      new webpack.BannerPlugin({
        banner: `;require('${require
          .resolve('source-map-support')
          .replace(/\\/g, '/')}').install();`,
        raw: true,
        entryOnly: false,
      })
    );
  }

  // Enable HMR globally if not.
  if (!config.plugins.find(p => p instanceof webpack.HotModuleReplacementPlugin)) {
    config.plugins.push(new webpack.HotModuleReplacementPlugin());
  }

  return config;
}
function tweakWebpackConfig ( module ) { const { default : webpackConfig = module } = module ; const config = handleWebpackConfig ( webpackConfig ) ; if ( ! config ) { throw new Error ( 'Not found webpack configuration. For multiple configurations in single file you must provide config with target "node".' ) ; } const hmrClientEntry = require . resolve ( './HmrClient' ) ; const addHmrClientEntry = ( entry , entryOwner ) => { const owner = entryOwner ; if ( Array . isArray ( owner [ entry ] ) ) { owner [ entry ] . splice ( - 1 , 0 , hmrClientEntry ) ; } else if ( typeof owner [ entry ] === 'string' ) { owner [ entry ] = [ hmrClientEntry , owner [ entry ] ] ; } else if ( typeof owner [ entry ] === 'function' ) { // Call function and try again with function result. owner [ entry ] = owner [ entry ] ( ) ; addHmrClientEntry ( entry , owner ) ; } else if ( typeof owner [ entry ] === 'object' ) { Object . getOwnPropertyNames ( owner [ entry ] ) . forEach ( name => addHmrClientEntry ( name , owner [ entry ] ) ) ; } } ; // Add HmrClient to every entries. addHmrClientEntry ( 'entry' , config ) ; if ( ! config . plugins ) { config . plugins = [ ] ; } // Add source-map support if configured. if ( config . devtool && config . devtool . indexOf ( 'source-map' ) >= 0 ) { config . plugins . push ( new webpack . BannerPlugin ( { banner : ` ${ require . resolve ( 'source-map-support' ) . replace ( / \\ / g , '/' ) } ` , raw : true , entryOnly : false , } ) ) ; } // Enable HMR globally if not. if ( ! config . plugins . find ( p => p instanceof webpack . HotModuleReplacementPlugin ) ) { config . plugins . push ( new webpack . HotModuleReplacementPlugin ( ) ) ; } return config ; }
Add hmrClient to all entries.
@param module
@returns {Promise.<config>}
Add hmrClient to all entries .