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

@shgysk8zer0/rollup-import

v1.2.4

Published

A RollUp plugin for importing modules from URLs, paths, and bare specifiers using import maps.

Downloads

705

Readme

rolllup-import

A RollUp plugin for importing modules from URLs, paths, and "bare specifiers" using import maps. You'll no longer need to npm i everything you need in front-end code.


CodeQL Node CI Lint Code Base

GitHub license GitHub last commit GitHub release GitHub Sponsors

npm node-current npm bundle size gzipped npm

GitHub followers GitHub forks GitHub stars Twitter Follow

Donate using Liberapay


Installation

npm i @shgysk8zer0/rollup-import

Supports

  • External impormap
    • JSON
    • YAML
  • Object { imports, scope } for importmap
  • Map new Map([[specifier, value]]) for importmap
  • Importing modules from URL and paths and "bare specifiers"
  • Resolving import.meta.url and import.meta.resolve('path.ext')

Not yet supported

  • import html from 'template.html' with { type: 'html' } - No spec yet and will have issues with TrustedTypes
  • import style from 'styles.css' with { type: 'style' } - Would require new CSSStyleSheet().replace() or style-src 'unsafe-inline'
  • import json from 'data.json' with { type: 'json' }
  • Parsing from <script type="importmap"> in an HTML file
  • Use of scope

Example

rollup.config.js

import {
  rollupImport, // Handles `import '@scope/package' resolving and fetching`
  rollupImportMeta // Handles `import.meta.url` and `import.meta.resolve()`,
} from '@shgysk8zer0/rollup-import';

import terser from '@rollup/plugin-terser';

// To load environment variables from `.env`
import { config } from 'dotenv';
config();

export default {
  input: 'src/index.mjs',
  plugins: [
    rollupImport(['path/to/importmap.json']),
    rollupImportMeta({
      // MUST be a valid URL
      baseURL: 'https://example.com', // Defaults to `process.env.URL` if set
      // MUST be a `file:` URL
      projectRoot: 'file:///home/user/Projects/my-project/', // Dfaults to `file:///${process.cwd()}/`
    }),
    terser(),
  ],
  output: {
    file: 'dest/index.js',
    format: 'iife'
  }
};

importmap.json

{
  "imports": {
    "leaflet": "https://unpkg.com/[email protected]/dist/leaflet-src.esm.js",
    "firebase/": "https://www.gstatic.com/firebasejs/9.16.0/",
    "@scope/package": "./node_modules/@scope/package/index.js",
    "@shgysk8zer0/polyfills": "https://unpkg.com/@shgysk8zer0/[email protected]/all.min.js",
    "@shgysk8zer0/polyfills/": "https://unpkg.com/@[email protected]/polyfills/"
  }
}

index.js

import '@scope/package';
import '@shgysk8zer0/polyfills';
import '@shgysk8zer0/polyfills/legacy/object.js'; // -> "https://unpkg.com/@[email protected]/polyfills/legacy/ojbect.js"
import { initializeApp } from 'firebase/firebase-app.js';
import { name } from './consts.js';

const stylesheet = document.createElement('link');
stylesheet.rel = 'stylesheet';
stylesheet.href = import.meta.resolve('styles.css');

document.head.append(stylesheet);

Notes

Using imports only, you may use only rollupImport or rollupImportMeta via @shgysk8zer0/rollup-import/import and @shgysk8zer0/rollup-import/meta respectively. To use with require(), you MUST import either/both using const {rollupImport, rollupImportMeta } = require('@shgysk8zer0/rollup-import').

This plugin works well if importing modules without bundling in the dev environment. In order to do this, however, you must include a <script type="importmap"> in your HTML - <script type="importmap" src="..."> will not work.