summaryrefslogtreecommitdiff
path: root/electron/service/commands/build.js
blob: 097f70135c5f7e225abcb5409dd0c3551d75a401 (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
'use strict'

const loadEnv = require('../utils/loadEnv')
loadEnv()
loadEnv('production')

const rm = require('rimraf')
const webpack = require('webpack')

const { error, done } = require('../utils/logger')
const { logWithSpinner, stopSpinner } = require('../utils/spinner')
const paths = require('../utils/paths')
// build renderer first
const webpackConfig = require('../config/renderer')
const config = require('../project.config')

logWithSpinner('Building for production...')

rm(paths.resolve(config.outputDir), (err) => {
  if (err) throw err

  webpack(webpackConfig, (err, stats) => {
    stopSpinner(false)

    if (err) throw err

    process.stdout.write(
      stats.toString({
        colors: true,
        modules: false,
        children: false,
        chunks: false,
        chunkModules: false,
      }) + '\n\n'
    )

    if (stats.hasErrors()) {
      error('Build failed with errors.\n')
      process.exit(1)
    }

    done('Build complete.\n')
  })
})