index.js 834 B

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