forked from okta/okta-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
38 lines (27 loc) · 1.09 KB
/
build.js
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
'use strict'
const shell = require('shelljs')
const chalk = require('chalk')
const fs = require('fs')
const NPM_DIR = `dist`
const BUNDLE_CMD = `cross-env NODE_ENV=production webpack --config webpack.config.js --output-library-target=umd -p`
const BUNDLES_DIR = `${NPM_DIR}/bundles`
shell.echo(`Start building...`)
shell.rm(`-Rf`, `${NPM_DIR}/*`)
shell.mkdir(`-p`, `./${BUNDLES_DIR}`)
// Bundle using webpack
if (shell.exec(BUNDLE_CMD).code !== 0) {
shell.echo(chalk.red(`Error: Webpack failed`))
shell.exit(1)
}
shell.echo(chalk.green(`Bundling completed`))
shell.cp(`-Rf`, [`src`, `package.json`, `LICENSE`, `THIRD-PARTY-NOTICES`, `*.md`], `${NPM_DIR}`)
shell.echo(`Modifying final package.json`)
let packageJSON = JSON.parse(fs.readFileSync(`./${NPM_DIR}/package.json`))
packageJSON.private = false
packageJSON.scripts.prepare = '';
// Remove "dist/" from the entrypoint paths.
['main'].forEach(function (key) {
packageJSON[key] = packageJSON[key].replace('dist/', '')
})
fs.writeFileSync(`./${NPM_DIR}/package.json`, JSON.stringify(packageJSON, null, 4))
shell.echo(chalk.green(`End building`))