1.提交创建配置
This commit is contained in:
parent
b3fdb7b390
commit
a3ac94db39
|
|
@ -0,0 +1,61 @@
|
||||||
|
const path = require('path')
|
||||||
|
const fs = require('fs')
|
||||||
|
var compressing = require('compressing')
|
||||||
|
const axios = require('axios')
|
||||||
|
const child_process = require('child_process')
|
||||||
|
|
||||||
|
function parseTime(time, format = 'yyyy-MM-dd hh:mm:ss') {
|
||||||
|
const date = time instanceof Date ? time : new Date(time)
|
||||||
|
|
||||||
|
const o = {
|
||||||
|
'M+': date.getMonth() + 1, // 月份
|
||||||
|
'd+': date.getDate(), // 日
|
||||||
|
'h+': date.getHours(), // 小时
|
||||||
|
'm+': date.getMinutes(), // 分
|
||||||
|
's+': date.getSeconds(), // 秒
|
||||||
|
'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
|
||||||
|
'S': date.getMilliseconds() // 毫秒
|
||||||
|
}
|
||||||
|
if (/(y+)/.test(format)) {
|
||||||
|
format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
|
||||||
|
}
|
||||||
|
for (const k in o) {
|
||||||
|
if (new RegExp('(' + k + ')').test(format)) {
|
||||||
|
format = format.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return format
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打包插件 v2.0
|
||||||
|
* youfool
|
||||||
|
*/
|
||||||
|
class IncrePack {
|
||||||
|
constructor(options) {
|
||||||
|
this.options = options
|
||||||
|
}
|
||||||
|
apply(compiler) {
|
||||||
|
const projectPath = path.join(__dirname, '../')
|
||||||
|
const distPath = projectPath + 'dist'
|
||||||
|
compiler.hooks.done.tap('IncrePack', async (compilation, callback) => {
|
||||||
|
// 排除开发环境
|
||||||
|
if (process.env.ENV !== 'development') {
|
||||||
|
|
||||||
|
const increName = `${this.options.name}.zip`
|
||||||
|
// 打包压缩
|
||||||
|
const tempFile = projectPath + '/' + increName
|
||||||
|
compressing.zip.compressDir(distPath, tempFile, { ignoreBase: true })
|
||||||
|
.then(() => {
|
||||||
|
// 剪切回dist目录下
|
||||||
|
fs.renameSync(tempFile, distPath + '/' + increName)
|
||||||
|
console.log('------------------打包成功------------------')
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.exports = IncrePack
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
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 app = connect()
|
||||||
|
|
||||||
|
app.use(
|
||||||
|
publicPath,
|
||||||
|
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}`)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue