index.js 894 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const {
  2. run
  3. } = require('runjs')
  4. const chalk = require('chalk')
  5. const config = require('../vue.config.js')
  6. const rawArgv = process.argv.slice(2)
  7. const args = rawArgv.join(' ')
  8. if (process.env.npm_config_preview || rawArgv.includes('--preview')) {
  9. const report = rawArgv.includes('--report')
  10. run(`vue-cli-service build ${args}`)
  11. const port = 9526
  12. const publicPath = config.publicPath
  13. var connect = require('connect')
  14. var serveStatic = require('serve-static')
  15. const app = connect()
  16. app.use(
  17. publicPath,
  18. serveStatic('./dist', {
  19. index: ['index.html', '/']
  20. })
  21. )
  22. app.listen(port, function () {
  23. console.log(chalk.green(`> Preview at http://localhost:${port}${publicPath}`))
  24. if (report) {
  25. console.log(chalk.green(`> Report at http://localhost:${port}${publicPath}report.html`))
  26. }
  27. })
  28. } else {
  29. run(`vue-cli-service build ${args}`)
  30. }