导入 V4
Anime.js v4 API 采用 ESM 优先的设计方法,支持出色的 Tree Shaking,同时还提供 CJS 版本和 UMD/ESM 打包。
ES 模块
使用 ES 模块语法通过 import
语句导入 Anime.js
import {
animate,
createTimeline,
createTimer,
// ...other methods
} from 'animejs';
或直接从 'dist/modules/index.js'
导入;
CommonJS 模块
使用 CommonJS 语法通过 require
函数导入 Anime.js
const {
animate,
createTimeline,
createTimer,
// ...other methods
} = require('animejs');
或直接从 'dist/modules/index.cjs'
导入;
全局 UMD 打包 (通用模块定义)
Anime.js 的 UMD 打包版本可以通过 script 标签全局使用
<script src="dist/bundles/anime.umd.min.js"></script>
<script>
const {
animate,
createTimeline,
createTimer,
// ...other methods
} = anime;
</script>
打包的 ES 模块
还提供打包和压缩的 ESM 版本,以便于嵌入
<script type="module">
import {
animate,
createTimeline,
createTimer,
// ...other methods
} from 'dist/bundles/anime.esm.min.js';
</script>