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

lua-distiller

v0.2.5

Published

Merge multiple lua file into one single lua file.

Downloads

19

Readme

lua-distiller

  1. Merge multiple lua file into one single lua file by analyzing require dependencies
  2. (optional) Minify the merged lua file by LuaSrcDiet
  3. (optional) Compile both merged file and minified file into luajit binary

分析 lua 代码中的 require 依赖,将分散的n个 lua 文件拼合成一个单一的 lua 文件

Install 安装

npm install coffee-script lua-distiller -g

LuaSrcDiet 是可选依赖。如果如果需要 minify 功能, 请确保 LuaSrcDiet.lua$PATH 中。

Usage 用法

Use in command line

lua-distill -i path/to/main.lua -o dist/dist.lua

Command line options 命令行参数

  -h, --help                  output usage information
  -V, --version               output the version number
  -o, --output [VALUE]        output directory
  -n, --onlyKeepMinifiedFile  only keep minified file
  -i, --input [VALUE]         path to main entrance lua file
  -x, --excludes [VALUE]      package names to be excluded, separated by: ","
  -m, --minify                minify merged lua file by LuaSrcDiet
  -j, --luajitify             compile merged lua file into luajit binary

How it works 原理

这个工具采用和 node-coffee-distiller 相同的工作原理, 用户给定一个入口文件,这个工具自动递归地分析入口文件中的依赖,然后将依赖和入口文件合并到一个输出结果。

这个工具派什么用?

当 lua 项目在一个完全嵌入的环境中被执行时,需要有一个方便发布快捷的生产环境发布部署载体。这个工具就是为了满足这个需求而设计的。

类似的工具包括 luac -o, luajit, squish, 但是这3个工具都需要手动维护合并列表,这无疑给始终在变化的项目增加了额外的工作量和出错的可能。

模拟 require

lua 的 require 实现是通过调用 package.preload 来确保一个模块只被加载一次。当分散的 lua 文件合并成一体之后, 不在存在外部需要 require 的文件,因此在合并的文件中采用模拟 require 的方式。

具体而言,使用一个全局变量 __DEFINED table 来保存所有合并入的依赖。 然后对每个被合并入的文件都使用 (function() end)() 来确保入口方法被执行前,被合并入的方法体已经完成自我的静态初始化。

优点

  1. 自动分析lua代码,无需手工维护合并列表
  2. 忽略被注释掉的 require
  3. 自动忽略项目中没有被用到的 lua 代码
  4. 可以嵌套地合并,比如一个项目中使用到n个第三方代码库,这些代码库都通过 distiller 合并过的话,将他们合并在一起不会产生冲突,是兼容的。

缺点

  1. 无法识别运行时程序拼合的模块名,比如 quick-x 中的 require(cc.PACKAGE_NAME .. ".functions") 是无法被识别的。并且我个人认为运行时拼合模块名是一种风险相对较大的实现,不推荐这样做。

License

MIT