From 58a66aa33d5449d4b2833f1f02427c999ecc7c08 Mon Sep 17 00:00:00 2001 From: Jhen Date: Sun, 10 Apr 2016 00:45:00 +0800 Subject: [PATCH] Add main proc build to package.js --- package.js | 18 ++++++++++++------ webpack.config.electron.js | 10 ++++++---- webpack.config.production.js | 8 ++++---- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/package.js b/package.js index 0ee2c293c4..23cb7baad0 100644 --- a/package.js +++ b/package.js @@ -4,6 +4,7 @@ const os = require('os'); const webpack = require('webpack'); const cfg = require('./webpack.config.production.js'); +const electronCfg = require('./webpack.config.electron.js'); const packager = require('electron-packager'); const del = require('del'); const exec = require('child_process').exec; @@ -52,12 +53,19 @@ if (version) { }); } +function build(cfg) { + return new Promise((resolve, reject) => { + webpack(cfg, (err, stats) => { + if (err) return reject(err); + resolve(stats); + }); + }); +} function startPack() { console.log('start pack...'); - webpack(cfg, (err, stats) => { - if (err) return console.error(err); - del('release') + build(electronCfg).then(() => build(cfg)) + .then(() => del('release')) .then(paths => { if (shouldBuildAll) { // build for all platforms @@ -73,11 +81,9 @@ function startPack() { // build for current platform only pack(os.platform(), os.arch(), log(os.platform(), os.arch())); } - }) - .catch(err => { + }).catch(err => { console.error(err); }); - }); } function pack(plat, arch, cb) { diff --git a/webpack.config.electron.js b/webpack.config.electron.js index c53c61e002..5d653480fc 100644 --- a/webpack.config.electron.js +++ b/webpack.config.electron.js @@ -7,10 +7,12 @@ const baseConfig = require('./webpack.config.base'); const config = Object.create(baseConfig); config.devtool = 'source-map'; -config.output.path = __dirname; -config.output.filename = './main.js'; +config.output = { + path: __dirname, + filename: './main.js' +}; config.entry = './main.development'; -config.plugins.push( +config.plugins = [ new webpack.BannerPlugin( 'require("source-map-support").install();', { raw: true, entryOnly: false } @@ -20,7 +22,7 @@ config.plugins.push( NODE_ENV: JSON.stringify('production') } }) -); +]; config.target = 'electron'; config.node = { __dirname: false, diff --git a/webpack.config.production.js b/webpack.config.production.js index 21f19c4129..e7c2c04429 100644 --- a/webpack.config.production.js +++ b/webpack.config.production.js @@ -15,7 +15,7 @@ config.entry = './app/index'; config.output.publicPath = '../dist/'; -config.module.loaders.push({ +config.module.loaders = config.module.loaders.concat([{ test: /\.global\.css$/, loader: ExtractTextPlugin.extract( 'style-loader', @@ -27,9 +27,9 @@ config.module.loaders.push({ 'style-loader', 'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]' ) -}); +}]); -config.plugins.push( +config.plugins = config.plugins.concat([ new webpack.optimize.OccurenceOrderPlugin(), new webpack.DefinePlugin({ __DEV__: false, @@ -44,7 +44,7 @@ config.plugins.push( } }), new ExtractTextPlugin('style.css', { allChunks: true }) -); +]); config.target = webpackTargetElectronRenderer(config);