esbuild#buildSync TypeScript Examples

The following examples show how to use esbuild#buildSync. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: esbuild.ts    From vue-components-lib-seed with MIT License 6 votes vote down vote up
async function combineDepsCss() {
  const PATH_RE = /^\.*\//
  const alljs = klawSync(`${cwd()}/dist/es`, {
    nofile: true,
    depthLimit: 0,
  }).map((dir) => dir.path + '/index.js')
  await init
  alljs.forEach((js) => {
    const [imports] = parse(fs.readFileSync(js, 'utf-8'))
    const cssFile = resolve(dirname(js), './index.css')

    if (fs.existsSync(cssFile)) {
      const selfCss = `import './index.css'\n`
      const depsCss = imports
        .flat()
        .map((item) => item.n)
        .filter((n) => !n.endsWith('utils'))
        .filter((n) => PATH_RE.test(n))
        .map((n) => `import '${n}/index.css'`)
        .join('\n')
      const styleFile = resolve(dirname(js), './style.js')

      fs.writeFileSync(styleFile, depsCss + '\n' + selfCss)

      buildSync({
        entryPoints: [styleFile],
        format: 'cjs',
        allowOverwrite: true,
        outfile: resolve(
          dirname(js).replace('/es/', '/lib/'),
          './style.js'
        ),
      })
    }
  })
}