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

connect-sourcemaps

v1.0.0

Published

Source maps to a code linking middleware

Downloads

7

Readme

Source maps to a code linking middleware

Tells to a browser where Source Maps for CSS and JavaScript code are located using SourceMap HTTP header or using an injection of annotations into a web servers response on the fly. This could be usefull when an injection of a source map annotations into a compiled code is not applicable or it is needed to use a source maps which are located in other place.

Installation

npm install connect-sourcemaps

Usage

This middleware should be used before any CSS and JavaScript serving middlewares to be able to post-process thiers response.

var connect = require('connect');
var connectSourceMaps = require('connect-sourcemaps');
var http = require('http');

var app = connect();

app.use('public', connectSourceMaps());
app.use('public', connect.static(__dirname));

http.createServer(app).listen(3000);

This assumes that source map files with the same name (plus .map) in the same directory

Respond with a SourceMap header

SourceMap header is used to tell a browser about a source maps location without any changes in a compiled files.

var connectSourceMaps = require('connect-sourcemaps');

app.use(connectSourceMaps({
  sourceMapHeader: true
}));

Respond with a deprecated X-SourceMap header

X-SourceMap header is used to tell a browser about a source maps location without any changes in a compiled files. Although this header had deprecated a few years ago.

var connectSourceMaps = require('connect-sourcemaps');

app.use(connectSourceMaps({
  xSourceMapHeader: true
}));

Respond with an annotation injected into a content on the fly

A sourceMappingURL comment will be appended to CSS and JavaScript files. Any existing annotations will be overrided.

var connectSourceMaps = require('connect-sourcemaps');

app.use(connectSourcemaps({
  annotate: true
}));

API

var connectSourceMaps = require('connect-sourcemaps');

connectSourceMaps(options)

options

  • sourceMapHeader

    Set this to true to respond source maps location using the SourceMap header. Default true.

  • xSourceMapHeader

    Set this to true to respond source maps location using the deprecated X-SourceMap header. Default false.

  • annotate

    Set this to true to inject an comment to the response. Default false.

  • suffix

    String to append to the requested URL to resolve a URL of source map file. Default .map. This assumes that source map files with the same name (plus .map) in the same directory.

  • sourceMapUrl

    This option gives full control over the source map URLs resolving. It takes a function that receives the object with a requested url as a parameter and returns URL of Source Map.

var connectSourceMaps = require('connect-sourcemaps');
var urlParse = require('url').parse;

app.use(connectSourceMaps({
  sourceMapUrl: function(file) {
    return 'http://hostname' + urlParse(file.url).pathname + this.suffix;
  }
}));

License

MIT