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

node-esm-loader

v0.3.0

Published

A webpack-like loader for Node

Downloads

360

Readme

node-esm-loader

A webpack-like loader library for Node

DISCLAIMER Loaders are still experimental in Node and may still change, which means this module is still experimental as well. Use at own risk and DO NOT rely on it in production.

This module is a simple wrapper around create-esm-loader to make it easier to set up a loader. In create-esm-loader you have to manually initialize, configure and export your loader, but this module reduces that so that all you need to do is configure the loader.

Installation

npm install --save-dev node-esm-loader

Usage

node-esm-loader will automatically export a loader based on how you configured it. You can use it by running Node as

node --import=node-esm-loader/register ./your/file.js

Or you can use the JavaScript api

// # register.js
import { register } from 'node:module';
register('node-esm-loader', import.meta.url, {

  // Optional, will search for a configuration file automatically if not specified
  data: {
    loaderConfig: './path/to/config.js',
  },

});

and then run Node as

node --import=./register.js ./your/file.js

For more info about this, see https://nodejs.org/api/module.html#customization-hooks. Note: since version 0.3.0, either Node >=18.19 or >=20.6 is required. Support for lower Node version has been dropped.

node-esm-loader loader will subsequently look for a configuration file in various places using cosmiconfig, where it also looks up the directory tree. My advice is to either use .loaderrc.js, or use a .config folder with .config/loaderrc.js, but loader.config.js will also work.

// .loaderrc.js, loader.config.js or .config/loaderrc.js
export default {
  loaders: [
    'vue-esm-loader',
    {
      test: /\.(png|gif|jpe?g)$/,
      type: 'asset/resource',
    },
    {
      transform(source, opts) {
        return { source: someTransformation(String(source)) };
      }
    },
  ],
};

For more info on what the loaders configuration should look like, have a look at create-esm-loader.

If you want to put the loader config in a different file, you can use

node --import=node-esm-loader/register ./your-file.js --loader-config=./path/to/config.js

When using this with mocha, create a .mocharc.cjs file that looks like this:

module.exports = {
  import: 'node-esm-loader/register',
};

Compatible Loaders

You can find a list of compatible loaders, here: