Skip to content

Commit

Permalink
添加vue-cli-3.0模板
Browse files Browse the repository at this point in the history
  • Loading branch information
nyj000 committed Apr 15, 2019
1 parent 32eef65 commit 9bfb757
Show file tree
Hide file tree
Showing 39 changed files with 15,575 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"comments": false,
"env": {
"web": {
"presets": [
["@vue/app", {
"polyfills": [
"es6.promise",
"es6.symbol"
]
}]
]
}
}
}
18 changes: 18 additions & 0 deletions .electron-vue/build.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require('path')

/**
* `electron-packager` options
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-packager.html
*/
module.exports = {
arch: 'x64',
asar: true,
appVersion: require('../package.json').version,
dir: path.join(__dirname, '../'),
icon: path.join(__dirname, '../build/icons/icon'),
ignore: /(^\/(src|test|\.[a-z]+|README|yarn|static|dist\/web))|\.gitkeep/,
out: path.join(__dirname, '../build'),
overwrite: true,
platform: process.env.BUILD_TARGET || 'all',
prune: true
}
131 changes: 131 additions & 0 deletions .electron-vue/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
'use strict'

process.env.NODE_ENV = 'production'

const { say } = require('cfonts')
const chalk = require('chalk')
const del = require('del')
const packager = require('electron-packager')
const webpack = require('webpack')
const Multispinner = require('multispinner')

const buildConfig = require('./build.config')
const mainConfig = require('./webpack.main.config')
const doneLog = chalk.bgGreen.white(' DONE ') + ' '
const errorLog = chalk.bgRed.white(' ERROR ') + ' '
const okayLog = chalk.bgBlue.white(' OKAY ') + ' '
const isCI = process.env.CI || false
const Service = require('@vue/cli-service/lib/Service')
const service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd())
const rendererConfig = {
_: ['build'],
'no-clean': true,
}

if (process.env.BUILD_TARGET === 'clean') clean()
else build()

function clean () {
del.sync(['build/*', '!build/icons', '!build/icons/icon.*'])
console.log(`\n${doneLog}\n`)
process.exit()
}

function build () {
greeting()

del.sync(['dist/electron/*', '!.gitkeep'])

const tasks = ['main', 'renderer']
const m = new Multispinner(tasks, {
preText: 'building',
postText: 'process'
})

let results = ''

m.on('success', () => {
process.stdout.write('\x1B[2J\x1B[0f')
console.log(`\n\n${results}`)
console.log(`${okayLog}take it away ${chalk.yellow('`electron-packager`')}\n`)
bundleApp()
})

pack(mainConfig).then(result => {
results += result + '\n\n'
m.success('main')
}).catch(err => {
m.error('main')
console.log(`\n ${errorLog}failed to build main process`)
console.error(`\n${err}\n`)
process.exit(1)
})

service.run('build', rendererConfig).then((result) => {
results += result + '\n\n'
m.success('renderer')
}).catch(err => {
m.error('renderer')
console.log(`\n ${errorLog}failed to build renderer process`)
console.error(`\n${err}\n`)
process.exit(1)
})
}

function pack (config) {
return new Promise((resolve, reject) => {
config.mode = 'production'
webpack(config, (err, stats) => {
if (err) reject(err.stack || err)
else if (stats.hasErrors()) {
let err = ''

stats.toString({
chunks: false,
colors: true
})
.split(/\r?\n/)
.forEach(line => {
err += ` ${line}\n`
})

reject(err)
} else {
resolve(stats.toString({
chunks: false,
colors: true
}))
}
})
})
}

function bundleApp () {
buildConfig.mode = 'production'
packager(buildConfig, (err, appPaths) => {
if (err) {
console.log(`\n${errorLog}${chalk.yellow('`electron-packager`')} says...\n`)
console.log(err + '\n')
} else {
console.log(`\n${doneLog}\n`)
}
})
}

function greeting () {
const cols = process.stdout.columns
let text = ''

if (cols > 85) text = 'lets-build'
else if (cols > 60) text = 'lets-|build'
else text = false

if (text && !isCI) {
say(text, {
colors: ['yellow'],
font: 'simple3d',
space: false
})
} else console.log(chalk.yellow.bold('\n lets-build'))
console.log()
}
40 changes: 40 additions & 0 deletions .electron-vue/dev-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')

hotClient.subscribe(event => {
/**
* Reload browser when HTMLWebpackPlugin emits a new index.html
*
* Currently disabled until jantimon/html-webpack-plugin#680 is resolved.
* https://github.com/SimulatedGREG/electron-vue/issues/437
* https://github.com/jantimon/html-webpack-plugin/issues/680
*/
// if (event.action === 'reload') {
// window.location.reload()
// }

/**
* Notify `mainWindow` when `main` process is compiling,
* giving notice for an expected reload of the `electron` process
*/
if (event.action === 'compiling') {
document.body.innerHTML += `
<style>
#dev-client {
background: #4fc08d;
border-radius: 4px;
bottom: 20px;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
color: #fff;
font-family: 'Source Sans Pro', sans-serif;
left: 20px;
padding: 8px 12px;
position: absolute;
}
</style>
<div id="dev-client">
Compiling Main Process...
</div>
`
}
})
Loading

0 comments on commit 9bfb757

Please sign in to comment.