Skip to content

Commit

Permalink
Use webpack to bundle the main electron process script
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop committed Apr 18, 2018
1 parent e26baa0 commit e9a6d8e
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ typings/

release
dist
nuclear.json
nuclear.json
bundle.electron.js
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "main.js",
"scripts": {
"start": "npm-run-all --parallel watch electron",
"electron": "electron .",
"electron:dev": "webpack --progress --colors --config=webpack.config.electron.js && electron ./bundle.electron.js",
"electron:prod": "webpack --progress --colors --config=webpack.config.electron.prod.js && cp index.prod.html dist && electron ./dist/bundle.electron.js",
"watch": "webpack-dev-server --inline --progress --env=dev",
"build:dist": "webpack --progress --colors --env=prod --define process.env.NODE_ENV=production",
"test": "mocha --require babel-register",
Expand Down Expand Up @@ -75,6 +76,7 @@
"isomorphic-fetch": "^2.2.1",
"lodash": "^4.17.5",
"mocha": "^5.0.0",
"node-loader": "^0.6.0",
"node-sass": "^4.7.2",
"nodebrainz": "^2.1.1",
"npm-run-all": "^4.1.2",
Expand Down Expand Up @@ -111,7 +113,7 @@
"dist/",
"resources/",
"index.prod.html",
"main.prod.js",
"dist/electron.bundle.js",
"mpris.js",
"package.json"
],
Expand Down
37 changes: 37 additions & 0 deletions webpack.config.electron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const webpack = require('webpack');
const path = require('path');
const HappyPack = require('happypack');

module.exports = {
entry: './main.js',
output: {
path: __dirname,
filename: 'bundle.electron.js'
},
module: {
loaders: [
{
test: /.jsx?$/,
use: 'happypack/loader?id=jsx',
exclude: /node_modules/
},
{
test: /.node$/,
use: 'node-loader'
}
]
},
plugins: [
new webpack.NamedModulesPlugin(),
new HappyPack({
id: 'jsx',
loaders: [ 'babel-loader' ]
}),
],
node: {
fs: "empty",
__dirname: false,
__filename: false
},
target: 'electron-main'
};
39 changes: 39 additions & 0 deletions webpack.config.electron.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const webpack = require('webpack');
const path = require('path');
const HappyPack = require('happypack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
entry: './main.prod.js',
output: {
path: __dirname,
filename: './dist/bundle.electron.js'
},
module: {
loaders: [
{
test: /.jsx?$/,
use: 'happypack/loader?id=jsx',
exclude: /node_modules/
},
{
test: /.node$/,
use: 'node-loader'
}
]
},
plugins: [
new webpack.NamedModulesPlugin(),
new HappyPack({
id: 'jsx',
loaders: [ 'babel-loader' ]
}),
new UglifyJsPlugin()
],
node: {
fs: "empty",
__dirname: false,
__filename: false
},
target: 'electron-main'
};
8 changes: 4 additions & 4 deletions webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ const config = {
module: {
loaders: [
{
test: /.jsx?$/,
use: 'happypack/loader?id=jsx',
test: /.jsx?$/,
use: 'happypack/loader?id=jsx',
exclude: /node_modules/
},
{
test: /.scss$/,
use: 'happypack/loader?id=scss'
test: /.scss$/,
use: 'happypack/loader?id=scss'
}, {
test: /\.css/,
loader: 'style-loader!css-loader?modules=true&localIdentName=[name]__[local]___[hash:base64:5]'
Expand Down

0 comments on commit e9a6d8e

Please sign in to comment.