Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/bs / src / .plugins / sourceMaps.ts
Size: Mime:
import { BannerPlugin } from 'webpack'
import { Configuration, Options } from '../typings'

const loader = {
  test: /\.js$/,
  use: [require.resolve('source-map-loader')],
  enforce: 'pre',
}

/**
 * https://www.npmjs.com/package/appdynamics
 * https://docs.appdynamics.com/display/PRO42/Install+the+Node.js+Agent#InstalltheNode.jsAgent-AdvancedInstructions
 * https://50.16.192.243:8181/controller/#/location=APPS_ALL_DASHBOARD&timeRange=last_15_minutes.BEFORE_NOW.-1.-1.15&application=85&dashboardMode=force
 */
// const appDynamics = `
// require('appdynamics').profile({
//   controllerHostName: '50.16.192.243',
//   controllerPort: 8181,
//   accountName: 'customer1',
//   accountAccessKey: '39eef0e5-d056-4ec1-96fd-edcd60dd8bda',
//   applicationName: 'PDN_ECOM_REACT',
//   tierName: 'WEB',
//   nodeName: 'process',
// });
// `
// ${process.env.SHOULD_USE_APP_DYNAMICS_WHICH_IS_80MB ? appDynamics : ''}

const BANNER_CONFIG = {
  banner: `
    require('source-map-support').install();
  `,
  raw: true,
  entryOnly: false,
}

/**
 * @see https://webpack.js.org/plugins/source-map-dev-tool-plugin/
 * @see https://webpack.js.org/plugins/banner-plugin/
 * @see https://reactjs.org/docs/cross-origin-errors.html
 * @see https://github.com/webpack-contrib/source-map-loader
 *
 * @name client
 *    @type {dev} inline or source-map-file for client
 *    @type {prod} hidden sourcemaps
 *
 * @name server
 *    @type {dev | prod | *} add source-map lib using BannerPlugin
 *      (so it's not part of webpack bundle & all chunks/output-files get it for node)
 *      @see https://github.com/mozilla/source-map
 *
 */
export default function sourceMapMiddleware(
  config: Configuration,
  options: Options
) {
  const { isServer, isDev } = options

  const FORCE_SOURCE_MAPS = process.env.FORCE_SOURCE_MAPS

  if (isServer) {
    const plugin = new BannerPlugin(BANNER_CONFIG)
    config.plugins.push(plugin)
  }

  // Include source maps for ANY node bundle so that we can support
  // nice stack traces for errors (the source maps get consumed by
  // the `node-source-map-support` module to allow for this).
  //
  // Always include source maps for any development build.
  // Allow for the following flag to force source maps even for production
  // builds.
  //
  // >>>>>>>>>>>>>>>>>>
  // !!!!!!!! WAS ISNODE
  // <<<<<<<<<<<<<<<<<<<<
  if (isServer || FORCE_SOURCE_MAPS) {
    // Produces an external source map (lives next to bundle output files).
    config.devtool = 'cheap-module-source-map'
  } else {
    if (isDev) {
      // Produces source map,
      // but no link to the source map is added to the source code
      // which allows re-tracing errors in production behind the scenes without exposing sourcemap
      // config.devtool = 'hidden-source-map'
      // @NOTE enabled for EASY sourcemap in prod
      // config.devtool = 'inline-source-map'

      // https://reactjs.org/docs/cross-origin-errors.html
      config.devtool = 'cheap-module-source-map'
    } else if (process.env.OPTIMIZE) {
      config.devtool = '@hidden-module-source-map'
    }

    // @todo ! - currently has issues with the worker loader...
    // config.module.rules.unshift(loader)

    if (process.env.FORCE_SOURCE_MAPS) {
      config.devtool = 'cheap-module-source-map'
    }
  }
}