summaryrefslogtreecommitdiff
path: root/.config/coc/extensions/node_modules/coc-css/esbuild.js
blob: bd641511e0312b527a7c6289d7291d5c63c5d307 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const path = require('path')

let entryPlugin = {
  name: 'entry',
  setup(build) {
    build.onResolve({filter: /^(index|server)\.ts$/}, args => {
      return {
        path: args.path,
        namespace: 'entry-ns'
      }
    })
    build.onLoad({filter: /.*/, namespace: 'entry-ns'}, args => {
      let contents = ''
      if (args.path == 'index.ts') {
        contents = `
        import {activate} from './src/index'
        export {activate}
        `
      } else if (args.path == 'server.ts') {
        contents = `require('./server/node/cssServerMain.ts')`
      } else {
        throw new Error('Bad path')
      }
      return {
        contents,
        resolveDir: __dirname
      }
    })
  }
}

async function start() {
  await require('esbuild').build({
    entryPoints: ['index.ts', 'server.ts'],
    define: {'process.env.NODE_ENV': JSON.stringify("production")},
    bundle: true,
    platform: 'node',
    target: 'node12.16',
    mainFields: ['module', 'main'],
    minify: true,
    sourcemap: true,
    external: ['coc.nvim'],
    outdir: path.resolve(__dirname, 'lib'),
    plugins: [entryPlugin]
  })
}

start().catch(e => {
  console.error(e)
})