搜索插件、代码仓与 APP 分类

插件详情v6.0.2

peanut

使用您的 Dart Web 应用程序的编译输出更新 GitHub gh-pages 分支。支持 'pub build' 和新的 'pub run build_runner'。

macOSWindowsLinux
近 30 天下载
2320
喜欢数
139
Pub 分数
150

安装插件

flutter pub add peanut

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Peanut 是一个 Dart 包,可自动将编译后的 Web 应用输出部署到 GitHub 的 gh-pages 分支。它支持传统的 'pub build' 和现代的 'pub run build_runner' 工作流,简化了 Flutter Web 应用的发布流程。专为希望在 GitHub Pages 上托管其 Web 应用的开发者设计,Peanut 只需最少配置即可处理构建和推送步骤。它可无缝集成到 CI/CD 流水线或 macOS、Windows 和 Linux 上的本地开发环境。

适合场景

  • 将 Flutter Web 应用部署到 GitHub Pages
  • 自动化构建和部署
  • 与 CI/CD 工作流集成
  • 从 Dart 项目发布静态 Web 内容
  • 在构建后简化 gh-pages 更新

主要特点

  • 支持 pub build 和 build_runner
  • 自动将 git 提交推送到 gh-pages
  • 跨平台兼容性
  • 所需设置最少
  • 适用于 Flutter Web 应用

适合对象

  • Flutter web 开发人员
  • GitHub Pages 用户
  • CI/CD 自动化
  • Dart 项目维护者
  • 寻求简单部署的开发者

使用建议

  • 需要 GitHub 仓库访问权限
  • 需要配置正确的 git 凭据
  • 不适用于非 GitHub 托管
  • 依赖 build_runner 以实现现代工作流程
  • 可能需要环境特定的设置

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Pub Package CI

Run flutter build web or dart pub run build_runner build and put the output in another branch. An easy way to update gh-pages.

Install

dart pub global activate peanut

or

flutter pub global activate peanut

Run

peanut

or

flutter pub global run peanut

This will build your project into a temporary directory, and then it will update the local gh-pages branch with the build output.

Read more about peanut in this article.

Options

$ peanut --help
Usage: peanut [<args>]

Arguments:
-d, --directories                The directories that should be built.
                                 (defaults to "web")
-b, --branch                     The git branch where the built content should
                                 be committed.
                                 (defaults to "gh-pages")
-c, --build-config               The configuration to use when running
                                 `build_runner`.
    --[no-]release               Flutter: enabled passes `--release`, otherwise
                                 passes `--profile`.
                                 Other: enabled passes `--release`, otherwise
                                 passes `--no-release`.
                                 (defaults to on)
-m, --message                    (defaults to "Built <directories>")
    --[no-]source-branch-info    Includes the name of the source branch and SHA
                                 in the commit message
                                 (defaults to on)
    --[no-]version-info          Includes the pubspec version of the package in
                                 the commit message
    --post-build-dart-script     Optional Dart script to run after all builds
                                 have completed, but before files are committed
                                 to the repository.
    --builder-options            Builder options YAML or a path to a file
                                 containing builder options YAML.
                                 See the README for details.
    --[no-]verbose               Print more details when running.
    --dry-run                    Verifies configuration and prints commands that
                                 would be executed, but does not do any work.
    --[no-]wasm                  Whether to build for WebAssembly (WASM).
    --extra-args                 Extra arguments to provide to the target CLI
                                 within a single string.
                                 Examples:
                                 --extra-args "--dart-define TEST_VAR=123"
                                 --extra-args "--dart-define --base-href=/base/"
-h, --help                       Prints usage information.
    --version                    Print the current version.

Configuration file

peanut also supports a configuration file. Convenient if you have one-off settings you'd rather not type every time you deploy.

The peanut.yaml from this repository:

# Configuration for https://pub.dev/packages/peanut
directories:
  - example

# The Dart script to run after the build is complete, but before the changes are committed.
# This script is run in the root of the package.
# The script has access to the root of the build output directory as the first argument.
post-build-dart-script: tool/post_build.dart

# Build options to pass to `build_runner`.
# These are merged with any existing `build.yaml` file.
builder-options:
  build_web_compilers|entrypoint:
    compilers:
      dart2wasm:
        args:
          - -O4
          - --no-strip-wasm
      dart2js:
        args:
          - --stage=dump-info-all
          - --no-frequency-based-minification
          - --no-source-maps
          - -O4
  build_web_compilers|dart2js_archive_extractor:
    filter_outputs: false

Post-build Dart script

You can optionally specify a Dart script to run after the build is complete, but before the changes are committed.

post-build-dart-script: tool/post_build.dart

This script is run from the root of the package.

It receives two arguments:

  1. The path to a temporary directory which contains the build output. For example, if you are building a single directory web, the output will be in a web subdirectory of this temporary directory.
  2. A JSON-encoded map where keys are the source directories that were built, and values are the corresponding output sub-directories within the temporary directory from the first argument.

For example, if you run peanut -d web, the script will be called with:

  • args[0]: /tmp/peanut.xyz (a temporary path)
  • args[1]: {"web":"."}

The index.html for the web build would be at /tmp/peanut.xyz/index.html.

Examples

  • https://github.com/dart-lang/sample-pop_pop_win/
    • Output: https://dart-lang.github.io/sample-pop_pop_win/
    • No custom configuration.
  • https://github.com/kevmoo/pubviz
    • Output: http://kevmoo.github.io/pubviz/
    • Custom peanut.yaml file to specify builder-options and example as the source directory.

Git tricks

The easiest way to push your gh-pages branch to github (without switching from your working branch) is:

git push origin --set-upstream gh-pages

To create (or update) your local gh-pages branch to match what's on the server.

git update-ref refs/heads/gh-pages origin/gh-pages

This is also useful if you want to undo a peanut run.

Publishing automation

For information about our publishing automation and release process, see https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

所属分类

依赖

依赖清单 13 项

源码仓库

使用此插件的项目