简单使用ESbuild打包工具

ESbuild打包器基于Golang开发,优点在于可多线程打包,直接编译成机器码,ESbuild提供的api可在JavaScript和golang使用,连Vite在很多场景都依赖了ESbuild打包(viet在开发环境下使用这个),支持TypeScript和jsx(tsx),css ESbuild支持ES6模块,cjs模块,对ES6+语法支持性好,可以直接打包css文件,json文件,ts文件 注意:esbuild并不对ts文件进行类型检查工作 安装 npm install esbuild 或者 yarn add esbuild 打包 .\node_modules.bin\esbuild app.jsx –outfile=build/index.js –bundle 或者 npx esbuild app.jsx –outfile=build/index.js –bundle 或者package.json “build”: “esbuild app.jsx –outfile=build/index.js –bundle” npm run build 或者 yarn build 例子(app.jsx) import React from 'react' import ReactDOM from 'react-dom' const App = () => { return ( <div> <h1>Hallo, Esbuild!</h1> </div> ) } ReactDOM.render( <App />, document.getElementById("app") ) index.html <div id="app"></div> <script src="./build/index.js"></script> 我本地打包只花64ms就打包好了 使用source map功能...

2022-02-07 · 1 min · Me