两种方法,使用 GUI 7zFM.exe,或者命令行或批处理文件。
1.0) GUI 方法。假设 7-Zip 与 shell 集成一起安装,因此您会在 Windows 资源管理器的上下文菜单(右键单击所选文件)中看到 7-Zip。
1.a) 进入您的插件文件夹。
1.b) 选择要包含在 .xpi 中的所有文件和文件夹。假设您在任何子文件夹中都没有要忽略的文件。如果这样做,您可能需要使用命令行选项。
1.c) 右键单击所选文件列表,找到7z 图标,选择Add to archive... 选项。
1.d) 弹出一个对话框。编辑 zip 文件的位置和名称,将 .zip 更改为 .xpi 等。
1.e) 请注意,如果您在同一个文件夹中创建 .xpi,以后不要重新归档它,因为您的插件会严重失败。您绝不希望 .xpi 意外地出现在您的 .xpi 中。我通常只是在父文件夹中创建它,方法是在文件名的开头添加..\,例如..\addon-1.2.3-fx.xpi
1.f) 7-Zip 有很多强大的压缩选项,并不是所有的 Firefox 都能处理。选择 Firefox 能够处理的设置。参考图片。
2.0) 命令行方法。假设您在 Windows 中,并且知道如何打开命令提示符、更改驱动器和目录(也称为文件夹)。
2.a) CD 到您的插件目录。
2.b) 使用最基本的 7-Zip 命令行。
"C:\Program Files\7-Zip\7z.exe" a -tzip addon-1.2.3-fx.xpi *
2.c) 您可以通过找到与上述 GUI 对应的确切命令行选项来获得较小的文件,即:
"C:\Program Files\7-Zip\7z.exe" a -tzip -mx=9 -mm=Deflate -mfb=258 -mmt=8 "addon-1.2.3-fx.xpi" *
请注意,使用 Deflate 压缩方法时没有 Dictionary size = 32kb 选项。否则,选项按顺序排列并与 GUI 相对应。
|-----------------------|---------|--------------|
| Option / Parameter | GUI | Command line |
|-----------------------|---------|--------------|
| Archive format | zip | -tzip |
| Compression level | Ultra | -mx=9 |
| Compression method | Deflate | -mm=Deflate |
| Dictionary size | 32 KB | (none) |
| Word size | 258 | -mfb=258 |
| Number of CPU threads | 8 | -mmt=8 |
|-----------------------|---------|--------------|
| Additional Parameters | | |
|-----------------------|---------|--------------|
| Recurse into Folders | (none) | -r |
| Multiple passes | (none) | -mpass=15 |
| Preserve Timestamps | (none) | -mtc=on |
| Ignore files in list | | -x@{ignore} |
|-----------------------|---------|--------------|
注意事项:
i) 多线程选项 (-mmt=8) 特定于我的具有 8 个内核的系统。如果您有更少的核心等,您需要将其降低到 6 或 4 或 2 或 1(即删除选项),或者如果您有更多,则需要增加。对于小型扩展,这两种方式都不会产生太大影响。
ii) 递归到文件夹的选项可能是也可能不是默认选项,因此指定此选项应确保正确递归。
iii) preserve windows timestamps 的选项(创建、访问、修改)无论如何都应默认为 on,因此可能不需要。
iv) ignore files in list 选项是具有文件列表和要排除的文件通配符的任何文件。
2.d) 高级主题#1:忽略文件列表(示例)
|----------------|------------------------------------|
| What to Ignore | Why to Ignore |
|----------------|------------------------------------|
| TODO.txt | Informal reminders of code to fix. |
| *.xpi | In case you forget warning above! |
| .ignore | Ignore the ignore file list. |
| ignore.txt | Same thing, if you used this name. |
|----------------|------------------------------------|
"C:\Program Files\7-Zip\7z.exe" a -tzip -mx9 -mm=Deflate -mfb=258 -mmt=8 -mpass=15 -mtc=on "addon-1.2.3-fx.xpi" * -x@ignore.txt
2.e) 高级主题 #2:批处理文件 (Windows CMD.EXE),假设是最近的窗口,即 21 世纪。这可以是简单而严格的,也可以是复杂而灵活的,只要您愿意。一般的平衡是假设您将在Command Prompt,在您正在处理的附加组件的顶级目录中,并且您已智能地将该目录命名为具有相同的 .xpi 文件的基本名称,例如addon-1.2.3-fx.xpi 附加 xpi 的 D:\dev\addon-1.2.3-fx 目录。此批处理文件做出此假设,并动态计算出用于 .xpi 的正确基本名称。
@ECHO OFF
REM - xpi.bat - batch file to create Mozilla add-on xpi using 7-Zip
REM - This finds the folder name, and discards the rest of the full path, saves in an environment variable.
FOR %%* IN (.) DO SET XPI=%%~nx*
REM - Uncomment the DEL line, or delete .xpi file manually, if it gets corrupted or includes some other junk by accident.
REM DEL "%XPI%.xpi"
REM - Command line which does everything the GUI does, but also lets you run several passes for the smallest .xpi possible.
"C:\Program Files\7-Zip\7z.exe" a -tzip -r -mx=9 -mm=Deflate -mfb=258 -mmt=8 -mpass=15 -mtc=on "%XPI%.xpi" * -x@ignore.txt
REM - Cleanup the environment variable.
SET XPI=