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

arenaless-bundler

v1.1.2

Published

Bundler based on rollup for ArenaLess

Downloads

802

Readme

ArenaLess-Bundler

重构版:ArenaLess的打包工具 Bundler based on rollup for ArenaLess

安装

npm install --save arenaless-bundler

使用

这是一个示例使用

import { build } from "arenaless-bundler";
import * as fs from "fs";

async function test(){
    let files_text:Record<string,string>={
        "index.ts":`import {hello} from "./hello/hi";
import hellots from "./hello/hi.ts?text";
import hellob64 from "./hello/hi.ts?base64";
hello();
console.log(hellots);
console.log(hellob64);
import JSON5 from "npm:json5";
console.log(JSON5.parse("{a:1}"))
import foo from "./foo.json";
console.log(foo)`,
        "hello/hi.ts":`export function hello():void{
            console.log("hello");
        }`,
        "foo.json":`{"bar":12345}`
    }
    // let imagebuf=fs.readFileSync("./image.png");
    // to uint array
    // let image=new Uint8Array(imagebuf);
    let files:Record<string,Uint8Array>={
        //"image.png": image,
    };
    for (let key in files_text) {
        files[key]=new TextEncoder().encode(files_text[key]);
    }
    let res=await build(files,"index.ts","{}",console,"cjs","{}",false);
    // console.log(res)
    return res;
};
(async ()=>{
    let start=Date.now();
    let res=await test();
    fs.writeFileSync("./test_output.js",res,{encoding:"utf-8"});
    console.log(`${Date.now()-start}ms`);
})();

有哪些特性?

1. 网络导入

如果你用过deno,你会发现十分的熟悉。在ArenaLess中,你可以从URL或者xxx:yyyy@...中导入模块。

import JSON5 from "npm:json5";
import JSON5 from "https://esm.sh/json5";

目前支持的前缀如下:

  • npm:... -> https://esm.sh/...
  • jsr:... -> https://esm.sh/jsr/...
  • http:https:

2. 虚拟的文件系统

为了实现在web环境可以打包构建,ArenaLess提供了一个虚拟文件系统。Record<string,Uint8Array>

3. 导入本地模块的特殊后缀

目前此功能只能支持本地模块,在线的模块用不了。

?binary 二进制导入

导入一个Uint8Array形式的二进制文件。

import xxx from "xxx?binary";

?text 文本导入

导入一个string形式的文本文件。

import xxx from "xxx?text";

?base64 base64导入

base64string导入一个文件。

import xxx from "xxx?base64";

?wasm 导入wasm实例

导入一个Promise<WebAssembly.Instance>形式的wasm文件。

这个相关的东西你可以到examples/wasm-hello-world查看

import hellowasm from "hellowasm.wasm?wasm";
hellowasm().then((instance)=>{
    console.log(instance.exports.add(1,100));
})

4. 默认的JSON格式导入

ArenaLess默认支持JSON的导入,你可以直接导入一个JSON文件。

// xxx.json
{"yyy":100,"zzz":"hello"}
import xxx from "xxx.json";
console.log(xxx.yyy);