index.js 892 B

1234567891011121314151617181920212223242526272829303132333435
  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 = 9527
  10. const publicPath = config.publicPath
  11. var connect = require('connect')
  12. var serveStatic = require('serve-static')
  13. const app = connect()
  14. app.use(
  15. publicPath,
  16. serveStatic('./dist', {
  17. index: ['index.html', '/']
  18. })
  19. )
  20. app.listen(port, function () {
  21. console.log(chalk.green(`> Preview at http://localhost:${port}${publicPath}`))
  22. if (report) {
  23. console.log(chalk.green(`> Report at http://localhost:${port}${publicPath}report.html`))
  24. }
  25. })
  26. } else {
  27. run(`vue-cli-service build ${args}`)
  28. }