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

@xfe-team/babel-plugin-fetch-import

v0.0.4

Published

A babel plugin allow you to import absolute http cdn url

Downloads

1

Readme

@xfe-team/babel-plugin-fetch-import

当前插件主要用于让 import 支持 http 引入形式, 就像 Deno 一样

安装

  npm install @xfe-team/babel-plugin-fetch-import --save-dev
  yarn add @xfe-team/babel-plugin-fetch-import --dev

配置

module.exports = {
    entry: {
        // ...
    },
    output: {
        // ...
    },
    module: {
        rules: [{
            test: /\.js|jsx$/,
            use: {
                loader: 'babel-loader',
                options: {
                    plugins: [
                         // FBI WARNING: 请确保当前插件在 import 被"编译"前处理
                        '@xfe-team/babel-plugin-fetch-import'
                    ]
                }
            }
        }]
    },
    // ...
}

使用

仅使用字符串的形式拉取:

  import zepto from 'FETCH:https://cdn.bootcss.com/zepto/1.0rc1/zepto.min.js';
  
  console.log(zepto);
  // 此时返回 zepto 字符串内容

作为 commonjs 模块拉取:

  import React from 'MODULE:https://unpkg.com/[email protected]/umd/react.development.js';
  
  console.log(React);
  // 此时返回 metaFlexible export 的对象

缓存

处于性能考虑, 默认情况下对于绝对路径如 https://unpkg.com/[email protected]/umd/react.development.js 会优先检查是否已经缓存, 无缓存时发起 http 请求拉去地址内容并缓存起来. 这样的策略是为了防止每一次编译导致都需要阻塞的拉去若干请求, 导致编译过慢.

由于这个缓存策略, 当前 plugin 也期望请求地址为静态不变的 url 地址, 如果远程请求地址发生变更, 请自行加入参数让当前 plugin 的缓存失效, 如: https://unpkg.com/[email protected]/umd/react.development.js?ts=123

当前缓存均保存在 ${cwd}/node_modules/.cache/@xfe-team/babel-plugin-fetch-import/ 下.

灵感

当前插件主要来源于: babel-plugin-import-customized-require Deno

功能补全

  1. 0.0.3 版本中加入了 __extension, 但仍存在用户可能冲突的使用到了这个 query string 参数. 后续应提供可更改 __extension 的配置项
  2. 0.0.3 版本中加入了 __extension, 当前库可以根据返回的 mine-type 自动识别正确的后缀, 尽管这个匹配率不一定会非常高.

ChangeLog

0.0.4

  • feat: 修复 import png 等非文本类型文件出错的问题

0.0.3

  • feat: 针对部分链接存在不存在后缀的, 如 'https://github.com/happy', 使用者可以在使用 __extension=js 来指引当前链接应该使用什么后缀, 如: 'https://github.com/happy?__extension=js'. 这将直接影响 module import 时应该用什么 loader 进行当前 url` 解析.

0.0.2

  • fix: 修复关于 module import 应该携带原 url 后缀, 这样便于其他 loader 进行进一步的解析的问题

0.0.1

  • init commit

作者

She Ailun