导入
Anime.js v4 API 采用以 ESM 为优先的设计,具有出色的 tree shaking 支持,同时还提供了 CJS 版本以及 UMD/ESM 包。
ES 模块
使用 import 语句通过 ES 模块语法导入 Anime.js:
import {
animate,
createTimeline,
createTimer,
// ...other methods
} from 'animejs';
或者直接从 'dist/modules/index.js' 导入;
CommonJS 模块
使用 require 函数通过 CommonJS 语法导入 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>