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

swc-import-glob-array-plugin

v1.0.2

Published

SWC plugin that expands glob patterns and imports them as an array

Downloads

4

Readme

SWC Import Glob Array Plugin

This plugin is a port of babel-plugin-import-glob-array from JavaScript to Rust for Speedy Web Compiler (SWC).

Before continuing, please understand that SWC plugins are distributed as WebAssembly binaries and are currently not backwards compatible, meaning that plugins may break frequently between versions. To ensure that you're using a version of this plugin that is compatible with your current @swc/core or next package(s), check out the compatibility table below.

Installation

Installation can be done via npm:

# npm
$ npm install --save-dev swc-import-glob-array-plugin

# yarn
$ yarn add -D swc-import-glob-array-plugin

# pnpm
$ pnpm add -D swc-import-glob-array-plugin

Then you'll add the plugin under jsc.experimental.plugins:

{
  "jsc": {
    "experimental": {
      "plugins": [
        [
          "swc-import-glob-array-plugin",
          {}
        ]
      ]
    }
  }
}

For more information on adding and configuration an SWC plugin, check out their documentation.

Usage

This plugin check the imports of each SWC file to determine if it contains a glob pattern. If it does, it will expand the single import to individual imports. As an example, let's say you have the following directory structure:

|- my-app
  |- docs
    |- hello.md
    |- world.md
  |- index.js

And index.js, which will get compiled by SWC, has the following import:

import docs from "./docs/*.md";

The single import will get parsed and expanded into:

import _iga1 from "./docs/hello.md";
import _iga2 from "./docs/world.md";

const docs = [ _iga1, _iga2 ];

Adding Import Metadata

In addition to expanding a single import, you can also import metadata information about where the file came from and what was imported via the special _importMeta property.

Using the example above, we can slightly modify our import statement:

import docs, { _importMeta as metadata } from "./docs/*.md";

Which will get parsed and expanded into:

import _iga1 from "./docs/hello.md";
import _iga2 from "./docs/world.md";

const docs = [ _iga1, _iga2 ];

const metadata = [
    {
        absolutePath: "/path/to/project/docs/hello.md",
        importedPath: "./docs/hello.md"
    },
    {
        absolutePath: "/path/to/project/docs/world.md",
        importedPath: "./docs/world.md"
    }
];

Compatibility

| swc-import-glob-array-plugin | @swc/core | |------------------------------|-----------------| | 1.0.1 | 1.3.44 ~ 1.3.47 | | 1.0.2 | 1.3.49 ~ 1.3.56 |