Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
877 views
in Technique[技术] by (71.8m points)

vuejs2 - Vue.js Build.js script does not terminate

    'use strict'
require('./check-versions')()

process.env.NODE_ENV = 'production'

const ora = require('ora')
const rm = require('rimraf')
const path = require('path')
const chalk = require('chalk')
const webpack = require('webpack')
const config = require('../config')
const webpackConfig = require('./webpack.prod.conf')

const spinner = ora('building for production...')
spinner.start()

rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  if (err) throw err
  webpack(webpackConfig, (err, stats) => {
    spinner.stop()
    if (err) throw err
    process.stdout.write(stats.toString({
      colors: true,
      modules: false,
      children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
      chunks: false,
      chunkModules: false
    }) + '

')

    if (stats.hasErrors()) {
      console.log(chalk.red('  Build failed with errors.
'))
      process.exit(1)
    }

    console.log(chalk.cyan('  Build complete.
'))
    console.log(chalk.yellow(
      '  Tip: built files are meant to be served over an HTTP server.
' +
      '  Opening index.html over file:// won't work.
'
    ))
  })
})

I have a legacy Vue.js project that used to be working fine. Recently when trying to build the project locally by running "npm run build". The script shows "Build complete" but it doesnt terminate itself. Build script build.js attached above.

If I proceed to commit and push the project to the Heroku hosting, the push will timeout because "npm run build" is part of the postinstall process and since the script doesnt terminate, Heroku deployment fail.

This is a snapshot of the package.json:

  "scripts": {
    "dev": "webpack-dev-server --inline --progress --host 0.0.0.0 --config build/webpack.dev.conf.js",
    "start": "node server.js",
    "postinstall": "npm run build",
    "build": "node build/build.js"
  },

This was not happening previously. Any idea why?

question from:https://stackoverflow.com/questions/66059985/vue-js-build-js-script-does-not-terminate

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
'use strict'
require('./check-versions')()

process.env.NODE_ENV = 'production'

const ora = require('ora')
const rm = require('rimraf')
const path = require('path')
const chalk = require('chalk')
const webpack = require('webpack')
const config = require('../config')
const webpackConfig = require('./webpack.prod.conf')

const spinner = ora('building for production...')
spinner.start()

rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  if (err) throw err
  webpack(webpackConfig, (err, stats) => {
    spinner.stop()
    if (err) throw err
    process.stdout.write(stats.toString({
      colors: true,
      modules: false,
      children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
      chunks: false,
      chunkModules: false
    }) + '

')

    if (stats.hasErrors()) {
      console.log(chalk.red('  Build failed with errors.
'))
      process.exit(1)
    }

    console.log(chalk.cyan('  Build complete.
'))
    console.log(chalk.yellow(
      '  Tip: built files are meant to be served over an HTTP server.
' +
      '  Opening index.html over file:// won't work.
'
    ))

    process.exit()
  })
})

Adding process.exit() solves my problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...