@automerge/automerge

中文文档
3.5.0发布于 2026/09/16MITTypeScriptESM + CJS零依赖近 30 天下载 34万

Javascript implementation of automerge, backed by @automerge/automerge-wasm

原始使用文档
文档目录6 节
  1. Automerge
  2. Quickstart
  3. Bundler setup
  4. Make some data
  5. Development
  6. Meta

Automerge

Automerge is a library of data structures for building collaborative applications, this package is the javascript implementation.

Detailed documentation is available at automerge.org but see the following for a short getting started guid.

Quickstart

First, install the library.

npm install @automerge/automerge

If you're writing a node application, you can skip straight to Make some data. If you're in a browser you need a bundler

Bundler setup

@automerge/automerge is a wrapper around a core library which is written in rust, compiled to WebAssembly and distributed as a separate package called @automerge/automerge-wasm. Browsers don't currently support WebAssembly modules taking part in ESM module imports, so you must use a bundler to import @automerge/automerge in the browser. There are a lot of bundlers out there, we have examples for common bundlers in the examples folder. Here is a short example using Webpack 5.

Assuming a standard setup of a new webpack project, you'll need to enable the asyncWebAssembly experiment. In a typical webpack project that means adding something like this to webpack.config.js

module.exports = {
  ...
  experiments: { asyncWebAssembly: true },
  performance: {       // we dont want the wasm blob to generate warnings
     hints: false,
     maxEntrypointSize: 512000,
     maxAssetSize: 512000
  }
};

Make some data

Automerge allows to separate threads of execution to make changes to some data and always be able to merge their changes later.

import * as automerge from "@automerge/automerge"
import * as assert from "assert"

let doc1 = automerge.from({
  tasks: [
    { description: "feed fish", done: false },
    { description: "water plants", done: false },
  ],
})

// Create a new thread of execution
let doc2 = automerge.clone(doc1)

// Now we concurrently make changes to doc1 and doc2

// Complete a task in doc2
doc2 = automerge.change(doc2, d => {
  d.tasks[0].done = true
})

// Add a task in doc1
doc1 = automerge.change(doc1, d => {
  d.tasks.push({
    description: "water fish",
    done: false,
  })
})

// Merge changes from both docs
doc1 = automerge.merge(doc1, doc2)
doc2 = automerge.merge(doc2, doc1)

// Both docs are merged and identical
assert.deepEqual(doc1, {
  tasks: [
    { description: "feed fish", done: true },
    { description: "water plants", done: false },
    { description: "water fish", done: false },
  ],
})

assert.deepEqual(doc2, {
  tasks: [
    { description: "feed fish", done: true },
    { description: "water plants", done: false },
    { description: "water fish", done: false },
  ],
})

Development

See HACKING.md

Meta

Copyright 2017–present, the Automerge contributors. Released under the terms of the MIT license (see LICENSE).

版本与发布记录

@automerge/automerge 共发布 138 个版本,首次发布于 2022/10/05;过去 12 个月发布了 19 个版本。

版本发布日期距今
3.5.0latest2026/09/161 个月前
3.4.12026/08/122 个月前
3.4.02026/08/013 个月前
3.3.22026/07/153 个月前
3.3.12026/07/133 个月前
3.3.02026/07/133 个月前

其他发布通道:preview → 3.0.0-preview.13,alpha → 3.0.0-alpha.4,next → 3.4.0-rev-frag-hex.3。

关于 @automerge/automerge 的常见问题

@automerge/automerge 是什么?

Javascript implementation of automerge, backed by @automerge/automerge-wasm

如何安装 @automerge/automerge?

在项目目录运行 npm install @automerge/automerge,或使用 pnpm add / yarn add / bun add。

@automerge/automerge 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@automerge/automerge 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@automerge/automerge 可以商用吗?

@automerge/automerge 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@automerge/automerge 的下载量有多少?

根据 npm 官方下载统计,@automerge/automerge 在 2026/10/07 – 2026/11/05 这 30 天内被下载 340,045 次,日均约 11,335 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@automerge/automerge 还在维护吗?

最新版本 3.5.0 发布于 2026/09/16(1 个月前);至今共发布 138 个版本,其中过去 12 个月发布了 19 个;首次发布于 2022/10/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。