Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新 #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions .electron-vue/dev-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let electronProcess = null
let manualRestart = false
let hotMiddleware

function logStats (proc, data) {
function logStats(proc, data) {
let log = ''

log += chalk.yellow.bold(`┏ ${proc} Process ${new Array((19 - proc.length) + 1).join('-')}`)
Expand All @@ -38,14 +38,14 @@ function logStats (proc, data) {
console.log(log)
}

function startRenderer () {
function startRenderer() {
return new Promise((resolve, reject) => {
rendererConfig.entry.renderer = [path.join(__dirname, 'dev-client')].concat(rendererConfig.entry.renderer)

const compiler = webpack(rendererConfig)
hotMiddleware = webpackHotMiddleware(compiler, {
log: false,
heartbeat: 2500
hotMiddleware = webpackHotMiddleware(compiler, {
log: false,
heartbeat: 2500
})

compiler.plugin('compilation', compilation => {
Expand All @@ -60,11 +60,10 @@ function startRenderer () {
})

const server = new WebpackDevServer(
compiler,
{
compiler, {
contentBase: path.join(__dirname, '../'),
quiet: true,
before (app, ctx) {
before(app, ctx) {
app.use(hotMiddleware)
ctx.middleware.waitUntilValid(() => {
resolve()
Expand All @@ -77,7 +76,7 @@ function startRenderer () {
})
}

function startMain () {
function startMain() {
return new Promise((resolve, reject) => {
mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main)

Expand Down Expand Up @@ -113,7 +112,7 @@ function startMain () {
})
}

function startElectron () {
function startElectron() {
electronProcess = spawn(electron, ['--inspect=5858', path.join(__dirname, '../dist/electron/main.js')])

electronProcess.stdout.on('data', data => {
Expand All @@ -128,7 +127,7 @@ function startElectron () {
})
}

function electronLog (data, color) {
function electronLog(data, color) {
let log = ''
data = data.toString().split(/\r?\n/)
data.forEach(line => {
Expand All @@ -145,7 +144,7 @@ function electronLog (data, color) {
}
}

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

Expand All @@ -163,7 +162,7 @@ function greeting () {
console.log(chalk.blue(' getting ready...') + '\n')
}

function init () {
function init() {
greeting()

Promise.all([startRenderer(), startMain()])
Expand All @@ -175,4 +174,4 @@ function init () {
})
}

init()
init()
Empty file removed dist/electron/.gitkeep
Empty file.
Empty file removed dist/web/.gitkeep
Empty file.
38 changes: 21 additions & 17 deletions src/index.ejs
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>electron-vue-admin</title>
<% if (htmlWebpackPlugin.options.nodeModules) { %>
<!-- Add `node_modules/` to global paths so `require` works properly in development -->
<script>
require('module').globalPaths.push('<%= htmlWebpackPlugin.options.nodeModules.replace(/\\/g, '\\\\') %>')
</script>
<% } %>
</head>
<body>
<div id="app"></div>
<!-- Set `__static` path to static files in production -->

<head>
<meta charset="utf-8">
<title>electron-vue-admin</title>
<% if (htmlWebpackPlugin.options.nodeModules) { %>
<!-- Add `node_modules/` to global paths so `require` works properly in development -->
<script>
if (process.env.NODE_ENV !== 'development') window.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
require('module').globalPaths.push('<%= htmlWebpackPlugin.options.nodeModules.replace(/\\/g, '\\\\
') %>')
</script>
<% } %>
</head>

<body>
<div id="app"></div>
<!-- Set `__static` path to static files in production -->
<script>
if (process.env.NODE_ENV !== 'development') window.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
</script>

<!-- webpack builds are automatically injected -->
</body>

<!-- webpack builds are automatically injected -->
</body>
</html>
</html>