You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

const { run } = require('runjs')
const chalk = require('chalk')
const config = require('../vue.config.js')
const rawArgv = process.argv.slice(2)
const args = rawArgv.join(' ')
if (process.env.npm_config_preview || rawArgv.includes('--preview')) {
const report = rawArgv.includes('--report')
run(`vue-cli-service build ${args}`)
const port = 9526
const publicPath = config.publicPath
var connect = require('connect')
var serveStatic = require('serve-static')
const path = require('path')
const app = connect()
// 静态文件服务 - 直接服务 dist 目录
app.use('/', serveStatic('./dist', {
index: ['index.html', '/']
}))
// SPA 路由支持 - 所有未匹配的路由都返回 index.html
app.use('*', (req, res) => {
res.sendFile(path.join(__dirname, '../dist/index.html'))
})
app.listen(port, function () {
console.log(chalk.green(`> Preview at http://localhost:${port}`))
if (report) {
console.log(chalk.green(`> Report at http://localhost:${port}/report.html`))
}
})
} else {
run(`vue-cli-service build ${args}`)
}