npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

remote-source-map-loader

v1.0.0

Published

Webpack loader that downloads remote sources.

Downloads

8

Readme

webpack-remote-source-map-loader

A Webpack loader that can locate source maps from their sourceMappingURL and fetches remote sources.

This is similar to source-map-loader but it has a few additional benefits:

Getting Started

Install:

npm install --save-dev remote-source-map-loader

Add a rule to your webpack.config.js:

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        enforce: 'pre',
        use: 'remote-source-map-loader',
      },
    ],
  },
};

Options

exclude

Type: String|RegExp|Function (can be repeated in an array) Default: () => false

A filter used to exclude sources from being processed. They will still appear in the resulting source map in order to keep the mappings intact.

The String form is equivalent to source => source === value.

The Regex form is equivalent to source => new RegExp(value).test(source).

For the Function form it should be of the type (source: string) => boolean. source is the value from the sources array in the source map. The returned value should be something that is truthy/falsey.

Example

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        enforce: 'pre',
        use: {
          loader: 'remote-source-map-loader',
          options: {
            exclude: [
              'virtualfile:%3Cmacro%3E',
              / \[synthetic:.*\] /,
              (source) =>
                source.startsWith('temp/node_modules/google-closure-library'),
            ],
          },
        },
      },
    ],
  },
};

cacheDirectory

Type: String Default: .remote-source-map-loader

Path to a directory to use for caching remote files.

Any remote files will be fetched and written to this directory. On subsequent executions, if the file exists in this directory then it will be read from there.

To disable caching set this to null or false.

Example

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        enforce: 'pre',
        use: {
          loader: 'remote-source-map-loader',
          options: {
            cacheDirectory: 'cache',
          },
        },
      },
    ],
  },
};

preFetchTransform

Type: Function Default: source => source

A transformation to apply to each source before it is fetched.

The transformed source value will be used for the remainder of the loader including fetching, other transformations and filters, and in the resulting source map.

The Function should be of the type (source: string) => string. source is the value from the sources array in the source map. The returned value should be a valid URL or file path.

A common use for this is to correct incorrect source maps.

Example

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        enforce: 'pre',
        use: {
          loader: 'remote-source-map-loader',
          preFetchTransform: (source) => {
            return source
              .replace(
                '../../../../../../../../lihaoyi/Github/sourcecode',
                'https://raw.githubusercontent.com/lihaoyi/sourcecode/0.2.1'
              )
              .replace(
                '../../../streams/_global/stImport/_global/streams/sources',
                'https://raw.githubusercontent.com/ScalablyTyped/Distribution/master'
              );
          },
        },
      },
    ],
  },
};

postFetchTransform

Type: Function Default:

(sourcePath) => {
  if (typeof sourcePath === 'string') {
    const parts = path.parse(path.normalize(sourcePath));
    const noRoot = path.join(parts.dir, parts.base);
    const relativeToAncestor = noRoot
      .split(path.sep)
      .filter((p) => p !== '..')
      .join(path.sep);
    return sourceDir
      ? path.join(sourceDir, relativeToAncestor)
      : relativeToAncestor;
  } else {
    const remotePath = path.join(sourcePath.hostname, sourcePath.pathname);
    return sourceDir ? path.join(sourceDir, remotePath) : remotePath;
  }
};

A transformation to apply to each source after it is fetched.

The transformed source will be used to emit the file and/or use in the resulting sources (if applicable).

The Function should be of the type (source: string|URL, defaultTransform: (source: string) => string) => string. source is the value from preFetchTransform. defaultTransform is the default transform which you can use to chain with your function.

The returned value should be a valid URL or file path.

A common use for this is to modify where the source is emitted to.

Example

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        enforce: 'pre',
        use: {
          loader: 'remote-source-map-loader',
          postFetchTransform: (source, defaultTransform) => {
            return defaultTransform(source).replace(/^node_modules/, 'libs');
          },
        },
      },
    ],
  },
};

includeContent

Type: Boolean|Function Default: () => true

Determines whether to include the source content in the source map.

The Boolean form is equivalent to () => value.

For the Function form it should be of the type (source: string) => boolean. source is the value from preFetchTransform. The returned value should be something that is truthy/falsey.

This has the same effect as setting noSources: true in the SourceMapDevToolPlugin but is done before the plugin, and it gives you the ability to control it independently for each source.

Example

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        enforce: 'pre',
        use: {
          loader: 'remote-source-map-loader',
          includeContent: false,
        },
      },
    ],
  },
};

emitContent

Type: Boolean|Function Default: () => true

Determines whether to emit the source content to a separate file.

The Boolean form is equivalent to () => value.

For the Function form it should be of the type (source: string) => boolean. source is the value from preFetchTransform. The returned value should be something that is truthy/falsey.

This is something that is currently not possible with the SourceMapDevToolPlugin.

The common use case for this is to separate your sources from your source map file for better control, especially when deploying to production.

Example

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        enforce: 'pre',
        use: {
          loader: 'remote-source-map-loader',
          emitContent: false,
        },
      },
    ],
  },
};

sourceDir

Type: String Default: 'src'

Path to use as the base directory for the default postFetchTransform function.

Example

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        enforce: 'pre',
        use: {
          loader: 'remote-source-map-loader',
          sourceDir: 'private',
        },
      },
    ],
  },
};