gnosis23 / hello-world-blog

还是 issues 里面写文章方便
https://bohao.work
0 stars 0 forks source link

esbuild #102

Open gnosis23 opened 2 years ago

gnosis23 commented 2 years ago

开一个新坑

特点

缺乏特性

资源

gnosis23 commented 2 years ago

代码切割

通过 splitting 选项开启(仅支持esm输出)

esbuild.build({
  entryPoints: [
    'src/main.js'
  ],
  bundle: true,
  format: 'esm',
  outdir: './build',
  splitting: true,
  plugins: []
}).catch(err => process.exit(1))

代码中需要使用 dynamic import 语法

window.a = () => import('./app.jsx');
gnosis23 commented 2 years ago

生态

gnosis23 commented 2 years ago

plugin

let plugin = {
  name: 'plugin-name',
  setup(build) {
    // onResolve可以把文件分到对应的namespace里,在onLoad里处理
    // onResolve到的文件还会递归onResolve
    build.onResolve({ filter: Reg }, args => ({
      path: args.path,
      namespace: 'plugin-namespace'
    }))
    build.onLoad({ filter: Reg2, namespace: 'plugin-namespace' }, async args => {
      return { contents }
      // return { errors }
    })
  }
}