acorn-parse-escodegen-generate-esm-broweser
可以在浏览器中运行,不需要nodejs环境,压缩后体积为155KB
使用 acorn
和escodegen
来 进行 javascript
源代码 和 抽象语法树
的相互转换的ES
模块,
把escodegen
和estraverse
和esutils
模块都从commonjs
模块改成ES
模块,acorn
使用自带的ES
模块
并且使用rollup
打包,并开启tree-shaking
和使用terser
代码压缩
依赖的模块
{
"dependencies": {
"acorn": "^6.2.1",
"escodegen": "^1.11.1",
"estraverse": "^4.2.0",
"esutils": "^2.0.3"
}
}
获取已压缩模块
ES 模块
从 cdn 获取
https://cdn.jsdelivr.net/gh/masx200/acorn-parse-escodegen-generate-esm-broweser@latest/dist/acorn-parse-escodegen-generate.esm.min.js
<script type="module">
import {
parse,
generate
} from "https://cdn.jsdelivr.net/gh/masx200/acorn-parse-escodegen-generate-esm-broweser@latest/dist/acorn-parse-escodegen-generate.esm.min.js";
</script>
安装模块
npm install --save https://github.com/masx200/acorn-parse-escodegen-generate-esm-broweser.git
或者
yarn add https://github.com/masx200/acorn-parse-escodegen-generate-esm-broweser.git
import { parse, generate } from "acorn-parse-escodegen-generate-esm-broweser";
var code = "var b=3";
var ast = parse(code);
var text = generate(ast);
A small, fast, JavaScript-based JavaScript parser
https://github.com/acornjs/acorn
https://npm.taobao.org/package/acorn
ECMAScript code generator
https://npm.taobao.org/package/escodegen
https://github.com/estools/escodegen