Updated: electron version->4 & webpack version -> 4

This commit is contained in:
Molunerfinn 2018-12-25 17:28:12 +08:00
parent 60ccd10e1a
commit eddd39309e
9 changed files with 3700 additions and 3097 deletions

View File

@ -72,6 +72,7 @@ function build () {
function pack (config) { function pack (config) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
config.mode = 'production'
webpack(config, (err, stats) => { webpack(config, (err, stats) => {
if (err) reject(err.stack || err) if (err) reject(err.stack || err)
else if (stats.hasErrors()) { else if (stats.hasErrors()) {
@ -99,6 +100,7 @@ function pack (config) {
function web () { function web () {
del.sync(['dist/web/*', '!.gitkeep']) del.sync(['dist/web/*', '!.gitkeep'])
webConfig.mode = 'production'
webpack(webConfig, (err, stats) => { webpack(webConfig, (err, stats) => {
if (err || stats.hasErrors()) console.log(err) if (err || stats.hasErrors()) console.log(err)

View File

@ -41,21 +41,21 @@ function logStats (proc, data) {
function startRenderer () { function startRenderer () {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
rendererConfig.entry.renderer = [path.join(__dirname, 'dev-client')].concat(rendererConfig.entry.renderer) rendererConfig.entry.renderer = [path.join(__dirname, 'dev-client')].concat(rendererConfig.entry.renderer)
rendererConfig.mode = 'development'
const compiler = webpack(rendererConfig) const compiler = webpack(rendererConfig)
hotMiddleware = webpackHotMiddleware(compiler, { hotMiddleware = webpackHotMiddleware(compiler, {
log: false, log: false,
heartbeat: 2500 heartbeat: 2500
}) })
compiler.plugin('compilation', compilation => { compiler.hooks.compilation.tap('compilation', compilation => {
compilation.plugin('html-webpack-plugin-after-emit', (data, cb) => { compilation.hooks.htmlWebpackPluginAfterEmit.tapAsync('html-webpack-plugin-after-emit', (data, cb) => {
hotMiddleware.publish({ action: 'reload' }) hotMiddleware.publish({ action: 'reload' })
cb() cb()
}) })
}) })
compiler.plugin('done', stats => { compiler.hooks.done.tap('done', stats => {
logStats('Renderer', stats) logStats('Renderer', stats)
}) })
@ -80,10 +80,10 @@ function startRenderer () {
function startMain () { function startMain () {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main) mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main)
mainConfig.mode = 'development'
const compiler = webpack(mainConfig) const compiler = webpack(mainConfig)
compiler.plugin('watch-run', (compilation, done) => { compiler.hooks.watchRun.tapAsync('watch-run', (compilation, done) => {
logStats('Main', chalk.white.bold('compiling...')) logStats('Main', chalk.white.bold('compiling...'))
hotMiddleware.publish({ action: 'compiling' }) hotMiddleware.publish({ action: 'compiling' })
done() done()
@ -114,8 +114,20 @@ function startMain () {
} }
function startElectron () { function startElectron () {
electronProcess = spawn(electron, ['--inspect=5858', path.join(__dirname, '../dist/electron/main.js')]) var args = [
'--inspect=5858',
path.join(__dirname, '../dist/electron/main.js')
]
// detect yarn or npm and process commandline args accordingly
if (process.env.npm_execpath.endsWith('yarn.js')) {
args = args.concat(process.argv.slice(3))
} else if (process.env.npm_execpath.endsWith('npm-cli.js')) {
args = args.concat(process.argv.slice(2))
}
electronProcess = spawn(electron, args)
electronProcess.stdout.on('data', data => { electronProcess.stdout.on('data', data => {
electronLog(data, 'blue') electronLog(data, 'blue')
}) })

View File

@ -6,14 +6,14 @@ const path = require('path')
const { dependencies } = require('../package.json') const { dependencies } = require('../package.json')
const webpack = require('webpack') const webpack = require('webpack')
const babelMinifyWebpackPlugin = require('babel-minify-webpack-plugin') const BabiliWebpackPlugin = require('babili-webpack-plugin')
let mainConfig = { let mainConfig = {
entry: { entry: {
main: path.join(__dirname, '../src/main/index.js') main: path.join(__dirname, '../src/main/index.js')
}, },
externals: [ externals: [
// ...Object.keys(dependencies || {}) ...Object.keys(dependencies || {})
], ],
module: { module: {
rules: [ rules: [
@ -73,7 +73,7 @@ if (process.env.NODE_ENV !== 'production') {
*/ */
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
mainConfig.plugins.push( mainConfig.plugins.push(
new babelMinifyWebpackPlugin(), new BabiliWebpackPlugin(),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"' 'process.env.NODE_ENV': '"production"'
}) })

View File

@ -8,8 +8,9 @@ const webpack = require('webpack')
const BabiliWebpackPlugin = require('babili-webpack-plugin') const BabiliWebpackPlugin = require('babili-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin') const CopyWebpackPlugin = require('copy-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin') const HtmlWebpackPlugin = require('html-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader')
/** /**
* List of node_modules to include in webpack bundle * List of node_modules to include in webpack bundle
@ -41,12 +42,21 @@ let rendererConfig = {
} }
} }
}, },
{
test: /\.styl(us)?$/,
use: [
'vue-style-loader',
'css-loader',
'stylus-loader'
]
},
{
test: /\.less$/,
use: ['vue-style-loader', 'css-loader', 'less-loader']
},
{ {
test: /\.css$/, test: /\.css$/,
use: ExtractTextPlugin.extract({ use: ['vue-style-loader', 'css-loader']
fallback: 'style-loader',
use: 'css-loader'
})
}, },
{ {
test: /\.html$/, test: /\.html$/,
@ -69,7 +79,9 @@ let rendererConfig = {
extractCSS: process.env.NODE_ENV === 'production', extractCSS: process.env.NODE_ENV === 'production',
loaders: { loaders: {
sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1', sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1',
scss: 'vue-style-loader!css-loader!sass-loader' scss: 'vue-style-loader!css-loader!sass-loader',
less: 'vue-style-loader!css-loader!less-loader',
stylus: 'vue-style-loader!css-loader!stylus-loader'
} }
} }
} }
@ -109,7 +121,8 @@ let rendererConfig = {
__filename: process.env.NODE_ENV !== 'production' __filename: process.env.NODE_ENV !== 'production'
}, },
plugins: [ plugins: [
new ExtractTextPlugin('styles.css'), new VueLoaderPlugin(),
new MiniCssExtractPlugin({filename: 'styles.css'}),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
filename: 'index.html', filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'), template: path.resolve(__dirname, '../src/index.ejs'),

View File

@ -29,7 +29,7 @@ before_install:
install: install:
#- export DISPLAY=':99.0' #- export DISPLAY=':99.0'
#- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & #- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- nvm install 8.9 - nvm install 10
- curl -o- -L https://yarnpkg.com/install.sh | bash - curl -o- -L https://yarnpkg.com/install.sh | bash
- source ~/.bashrc - source ~/.bashrc
- npm install -g xvfb-maybe - npm install -g xvfb-maybe

View File

@ -111,22 +111,22 @@
"css-loader": "^0.28.4", "css-loader": "^0.28.4",
"del": "^3.0.0", "del": "^3.0.0",
"devtron": "^1.4.0", "devtron": "^1.4.0",
"electron": "1.8.8", "electron": "4.0.0",
"electron-builder": "^19.19.1", "electron-builder": "^19.19.1",
"electron-debug": "^1.4.0", "electron-debug": "^1.4.0",
"electron-devtools-installer": "^2.2.0", "electron-devtools-installer": "^2.2.0",
"eslint": "^4.4.1", "eslint": "^4.4.1",
"eslint-config-standard": "^10.2.1", "eslint-config-standard": "^10.2.1",
"eslint-friendly-formatter": "^3.0.0", "eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.9.0", "eslint-loader": "^2.1.1",
"eslint-plugin-html": "^3.1.1", "eslint-plugin-html": "^3.1.1",
"eslint-plugin-import": "^2.7.0", "eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.1.1", "eslint-plugin-node": "^5.1.1",
"eslint-plugin-promise": "^3.5.0", "eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1", "eslint-plugin-standard": "^3.0.1",
"extract-text-webpack-plugin": "^3.0.0", "extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2", "file-loader": "^3.0.1",
"html-webpack-plugin": "^2.30.1", "html-webpack-plugin": "^3.2.0",
"inject-loader": "^3.0.0", "inject-loader": "^3.0.0",
"karma": "^1.3.0", "karma": "^1.3.0",
"karma-chai": "^0.1.0", "karma-chai": "^0.1.0",
@ -136,6 +136,7 @@
"karma-sourcemap-loader": "^0.3.7", "karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "^0.0.31", "karma-spec-reporter": "^0.0.31",
"karma-webpack": "^2.0.1", "karma-webpack": "^2.0.1",
"mini-css-extract-plugin": "0.4.0",
"mocha": "^3.0.2", "mocha": "^3.0.2",
"multispinner": "^0.2.1", "multispinner": "^0.2.1",
"node-loader": "^0.6.0", "node-loader": "^0.6.0",
@ -143,17 +144,18 @@
"pug-loader": "^2.3.0", "pug-loader": "^2.3.0",
"require-dir": "^0.3.0", "require-dir": "^0.3.0",
"spectron": "^3.7.1", "spectron": "^3.7.1",
"style-loader": "^0.18.2", "style-loader": "^0.23.1",
"stylus": "^0.54.5", "stylus": "^0.54.5",
"stylus-loader": "^3.0.1", "stylus-loader": "^3.0.1",
"url-loader": "^0.5.9", "url-loader": "^1.1.2",
"vue-html-loader": "^1.2.4", "vue-html-loader": "^1.2.4",
"vue-loader": "^13.0.5", "vue-loader": "^15.4.2",
"vue-style-loader": "^3.0.1", "vue-style-loader": "^4.1.2",
"vue-template-compiler": "^2.4.2", "vue-template-compiler": "^2.4.2",
"webpack": "^3.5.2", "webpack": "^4.15.1",
"webpack-dev-server": "^2.7.1", "webpack-cli": "^3.0.8",
"webpack-hot-middleware": "^2.18.2", "webpack-dev-server": "^3.1.4",
"webpack-merge": "^4.1.0" "webpack-hot-middleware": "^2.22.2",
"webpack-merge": "^4.1.3"
} }
} }

View File

@ -7,9 +7,6 @@
/* eslint-disable */ /* eslint-disable */
// Set environment for development
process.env.NODE_ENV = 'development'
// Install `electron-debug` with `devtron` // Install `electron-debug` with `devtron`
require('electron-debug')({ showDevTools: false }) require('electron-debug')({ showDevTools: false })
@ -24,15 +21,4 @@ require('electron').app.on('ready', () => {
}) })
// Require `main` process to boot app // Require `main` process to boot app
if (process.env.DEBUG_ENV === 'debug') { require('./index')
require('babel-core/register')({
'presets': [
['env', {
'targets': {
'node': true
}
}]
]
})
}
require('./index')

View File

@ -477,17 +477,17 @@ const shortKeyHash = {
upload: uploadClipboardFiles upload: uploadClipboardFiles
} }
const isSecondInstance = app.makeSingleInstance(() => { const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit()
} else {
if (settingWindow) { if (settingWindow) {
if (settingWindow.isMinimized()) { if (settingWindow.isMinimized()) {
settingWindow.restore() settingWindow.restore()
} }
settingWindow.focus() settingWindow.focus()
} }
})
if (isSecondInstance) {
app.quit()
} }
if (process.platform === 'win32') { if (process.platform === 'win32') {

6676
yarn.lock

File diff suppressed because it is too large Load Diff