初始化
This commit is contained in:
38
build/index.js
Normal file
38
build/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
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
|
||||
const mountPath = typeof publicPath === 'string' && publicPath.endsWith('/')
|
||||
? publicPath.slice(0, -1)
|
||||
: publicPath
|
||||
|
||||
var connect = require('connect')
|
||||
var serveStatic = require('serve-static')
|
||||
const app = connect()
|
||||
|
||||
app.use(
|
||||
mountPath,
|
||||
serveStatic('./dist', {
|
||||
index: ['index.html', '/']
|
||||
})
|
||||
)
|
||||
|
||||
app.listen(port, function () {
|
||||
console.log(chalk.green(`> Preview at http://localhost:${port}${publicPath}`))
|
||||
if (report) {
|
||||
console.log(chalk.green(`> Report at http://localhost:${port}${publicPath}report.html`))
|
||||
}
|
||||
|
||||
})
|
||||
} else {
|
||||
run(`vue-cli-service build ${args}`)
|
||||
}
|
||||
16
build/preview-static.js
Normal file
16
build/preview-static.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const connect = require('connect');
|
||||
const serveStatic = require('serve-static');
|
||||
const chalk = require('chalk');
|
||||
const path = require('path');
|
||||
|
||||
const port = process.env.PORT ? Number(process.env.PORT) : 9526;
|
||||
const mountPath = '/srs'; // 与生产 publicPath 保持一致
|
||||
const distDir = path.resolve(__dirname, '..', 'dist');
|
||||
|
||||
const app = connect();
|
||||
app.use(mountPath, serveStatic(distDir, { index: ['index.html', '/'] }));
|
||||
|
||||
app.listen(port, () => {
|
||||
const url = `http://localhost:${port}${mountPath}/`;
|
||||
console.log(chalk.green(`> Static preview running at ${url}`));
|
||||
});
|
||||
Reference in New Issue
Block a user