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

importmap-resolver

v0.4.3

Published

Resolve module names with importmap

Downloads

6

Readme

importmap-resolver

license

This package is for resolving module names with importmap.

Installation

npm install --save-dev importmap-resolver

Command Line Usage

Create an importmap file

First, create the file .importmap.yaml or .importmap.yml. This package searches it from the working directory toward the root and uses the first found one.

You can use regular expressions as well as strings in the map. Note its order because the mappings written earlier are preferred.

# Mapping with strings
a: https://example-a.ex/a.js
b: https://example-b.ex/b.js

# Mapping with the regular expressions
(.+): https://example-$1.ex/$1.js

Also, note that YAML distinguishes between strings, numbers, etc. Therefore, 1: 2 must be written as '1': '2'.

Execute command

importmap <include-path> [options]

If a directory path is specified, search files under it with the extension .js or .mjs recursively.

Options

  • --minify: Enable code minification.

  • --ecma <version>: Specify an ECMAScript version such as 5, 2015, etc. It helps to optimize code minification.

API Usage

First, load this package with the following import statement.

import { resolve, replace, execute } from "importmap-resolver";

Functions

  • resolve(moduleName: string): string

    Convert the module name to resolved one.

  • replace(code: string): string

    Convert module names in the code to resolved ones.

  • execute(includePath: string, shouldMinify = false, minifyOptions?: object): void

    The command process uses this function. The minify options are only available from API.

Loading AMD (Asynchronous Module Definition)

This package can convert the import statements loading AMD. Meet these conditions to use this feature.

  • Resolved module names (URL or GET parameter) include the string amd or umd sandwiched between the symbols.
  • Specified modules output the variable declared in each import statement.

See the following examples for more information.

// 'react.js' outputs 'React'
import React from './amd/react.js'
import * as React from './amd/react.js'
// ↓
import './amd/react.js'

// 'react.umd.js' outputs 'useState'
import { useState } from './react.umd.js'
// ↓
import './react.umd.js'

// 'react.js' outputs 'React'
import React, { useState as ustate } from './react.js?amd';
// ↓
import './react.js?amd'; const { useState: ustate } = React;

// 'react.js' outputs 'React'
import React, * as react from './react.js?name=val&module=umd';
// ↓
import './react.js?name=val&module=umd'; const react = React;