index.js 737 B

12345678910111213141516171819202122232425262728293031
  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. run(`vue-cli-service build ${args}`)
  8. const port = 9526
  9. const publicPath = config.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(
  21. chalk.green(`> Listening at http://localhost:${port}${publicPath}`)
  22. )
  23. })
  24. } else {
  25. run(`vue-cli-service build ${args}`)
  26. }