pack.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const fs = require('fs-extra')
  2. const ora = require('ora')
  3. const chalk = require('chalk')
  4. const webpack = require('webpack')
  5. const config = require('../build/config-reverse')
  6. module.exports = env => {
  7. const spinner = ora(`Building for ${env}...`)
  8. spinner.start()
  9. fs.emptyDirSync(config.distPath)
  10. const webpackConfig = require('../build/webpack')(env, config)
  11. const compiler = webpack(webpackConfig)
  12. compiler.run((err, stats) => {
  13. spinner.stop()
  14. if (err) {
  15. console.error(err.stack || err)
  16. if (err.details) {
  17. console.error(err.details)
  18. }
  19. return
  20. }
  21. process.stdout.write(
  22. stats.toString({
  23. children: false,
  24. chunks: false,
  25. colors: true,
  26. modules: false,
  27. chunkModules: false,
  28. hash: false,
  29. }) +
  30. '\n\n'
  31. )
  32. if (stats.hasErrors()) {
  33. return console.log(chalk.white.bgRed('Build failed.\n'))
  34. }
  35. if (stats.hasWarnings()) {
  36. return console.log(chalk.white.bgGreenBright(
  37. 'Build success, but with warnings.\n'))
  38. }
  39. console.log(chalk.white.bgGreen('Build success.\n'))
  40. })
  41. }