index.js 917 B

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