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

@tbranyen/babel-plugin-bare-import-rewrite

v1.3.0-1

Published

Babel plugin to rewrite bare imports for browser use.

Downloads

5

Readme

babel-plugin-bare-import-rewrite

Travis CI Greenkeeper badge NPM Version NPM Downloads BSD-3-Clause

Babel plugin to rewrite bare imports. In theory this will become obsolete if/when browsers get support for import maps. See domenic/package-name-maps for information about the proposal.

Install babel-plugin-bare-import-rewrite

This module requires node.js 8 or above and @babel/core.

npm i babel-plugin-bare-import-rewrite

Usage

Add bare-import-rewrite to plugins in your babel settings.

Settings

{
	"plugins": [
		["bare-import-rewrite", {
			"modulesDir": "/node_modules",
			"rootBaseDir": ".",
			"alwaysRootImport": [],
			"ignorePrefixes": ["//"]
		}]
	]
}

If the plugin settings object is omitted the defaults are used:

{
	"plugins": ["bare-import-rewrite"]
}

modulesDir

The URL path in which node_modules will be published on the web server. This must always be an absolute directory without hostname. Default "/node_modules".

rootBaseDir

The project base directory. This should contain the package.json and node_modules of the application. Default process.cwd().

alwaysRootImport

This contains a list of module bare names which should always be forced to import from the root node_modules. ['**'] can be used to specify that all modules should be resolved from the root folder. No attempt is made to verify that overridden modules are compatible. Each element is used as a pattern to be processed with minimatch. Default [].

neverRootImport

This contains a list of module bare names which should never be forced to imported from the root node_modules. Processed with minimatch. Default [].

This example will force all modules to be loaded from the root node_modules except for some-exception:

{
	"alwaysRootImport": ["**"],
	"neverRootImport": ["some-exception"]
}

fsPath

Setting this option true forces use of platform specific path separators. This should generally be used when using absolute filesystem paths for bundling.

ignorePrefixes

This option can be set to an array of strings. Each represents a module name prefix to be ignored.

extensions

A list of extensions to use in resolver. Default ['.mjs', '.js', '.json'].

.resolve(importModule, sourceFileName, pluginOptions) - Resolve absolute path.

This function is used internally by the babel plugin, is exposed so it can be used by analyzers to build a list of scripts being imported. The pluginOptions argument takes the same values as the babel plugin and uses the same defaults.

const {resolve} = require('babel-plugin-bare-import-rewrite');

const importModule = '@polymer/lit-element';
const pluginOptions = {
	"alwaysRootImport": ["@polymer/*"],
};
try {
	const absPath = resolve(importModule, __filename, pluginOptions);
	console.log(`The requested module ${importModule} is in ${absPath}.`);
} catch (e) {
	console.error(`Cound not resolve ${importModule}:`, e);
}

Running tests

Tests are provided by xo and ava.

npm install
npm test

Attribution

This module is based on code found in polymer-build and polymer-analyzer.