diff --git a/package-lock.json b/package-lock.json index bbb89c4..2251e56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -825,6 +825,59 @@ } } }, + "aws-sdk": { + "version": "2.254.1", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.254.1.tgz", + "integrity": "sha512-v4hrK7KYFLLRDMERmT3c7jstl5LAqH8iCz5sV9u+wvW9csYzIAQdubfjkpzVk4qN78R9J6S+VmIL9eva7pgY+w==", + "dev": true, + "requires": { + "buffer": "4.9.1", + "events": "1.1.1", + "ieee754": "1.1.8", + "jmespath": "0.15.0", + "querystring": "0.2.0", + "sax": "1.2.1", + "url": "0.10.3", + "uuid": "3.1.0", + "xml2js": "0.4.17" + }, + "dependencies": { + "ieee754": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.8.tgz", + "integrity": "sha1-vjPUCsEO8ZJnAfbwii2G+/0a0+Q=", + "dev": true + }, + "punycode": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz", + "integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0=", + "dev": true + }, + "sax": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz", + "integrity": "sha1-e45lYZCyKOgaZq6nSEgNgozS03o=", + "dev": true + }, + "url": { + "version": "0.10.3", + "resolved": "https://registry.npmjs.org/url/-/url-0.10.3.tgz", + "integrity": "sha1-Ah5NnHcF8hu/N9A861h2dAJ3TGQ=", + "dev": true, + "requires": { + "punycode": "1.3.2", + "querystring": "0.2.0" + } + }, + "uuid": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", + "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==", + "dev": true + } + } + }, "aws-sign2": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", @@ -7923,6 +7976,12 @@ "merge-stream": "^1.0.1" } }, + "jmespath": { + "version": "0.15.0", + "resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.15.0.tgz", + "integrity": "sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc=", + "dev": true + }, "joi": { "version": "11.4.0", "resolved": "https://registry.npmjs.org/joi/-/joi-11.4.0.tgz", @@ -15897,6 +15956,25 @@ "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==", "dev": true }, + "xml2js": { + "version": "0.4.17", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.17.tgz", + "integrity": "sha1-F76T6q4/O3eTWceVtBlwWogX6Gg=", + "dev": true, + "requires": { + "sax": ">=0.6.0", + "xmlbuilder": "^4.1.0" + } + }, + "xmlbuilder": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-4.2.1.tgz", + "integrity": "sha1-qlijBBoGb5DqoWwvU4n/GfP0YaU=", + "dev": true, + "requires": { + "lodash": "^4.0.0" + } + }, "xtend": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-2.1.2.tgz", diff --git a/package.json b/package.json index 16f397f..351d8ac 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,10 @@ "description": "Barebones starter kit with TypeScript, React, react-router, and Jest", "main": "dist/main.js", "scripts": { - "build": "", - "dev:main": "cross-env NODE_ENV=development webpack --config webpack.main.js && ./node_modules/.bin/electron dist/main.js", + "build": "npm run build:renderer && npm run build:main", + "build:main": "webpack --config webpack.main.js", + "build:renderer": "webpack --config webpack.renderer.prod.js", + "dev:main": "cross-env NODE_ENV=development webpack --config webpack.main.js && electron dist/main.js", "dev:renderer": "cross-env NODE_ENV=development webpack-dev-server --config webpack.renderer.js", "lint": "./node_modules/.bin/tslint -c \"tslint.json\" -e \"node_modules/**/*\" \"./src/**/*.{ts,tsx}\"", "precommit-msg": "echo 'Pre-commit checks...' && exit 0", @@ -30,6 +32,7 @@ "@types/react": "^16.3.17", "@types/react-dom": "^16.0.6", "@types/react-router-dom": "^4.2.7", + "aws-sdk": "^2.254.1", "babel-core": "^6.26.3", "babel-loader": "^7.1.4", "babel-plugin-import": "^1.7.0", diff --git a/src/main.ts b/src/main.ts index c79adb1..5430c01 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,54 +1,45 @@ import { app, BrowserWindow } from 'electron'; import * as path from 'path'; - -require('electron-reload')(__dirname); +import * as url from 'url'; let mainWindow: Electron.BrowserWindow; -function createWindow() { - // Create the browser window. +const createWindow = () => { mainWindow = new BrowserWindow({ height: 600, width: 900 }); if (process.env.NODE_ENV === 'development') { + console.log('Loading development environment'); mainWindow.loadURL('http://localhost:8080'); mainWindow.webContents.openDevTools(); } else { - mainWindow.loadFile(path.join(__dirname, 'index.html')); + console.log('Loading non-development environment'); + mainWindow.loadURL( + url.format({ + pathname: path.join(__dirname, 'index.html'), + protocol: 'file:', + slashes: true + }) + ); } - // Emitted when the window is closed. mainWindow.on('closed', () => { - // Dereference the window object, usually you would store windows - // in an array if your app supports multi windows, this is the time - // when you should delete the corresponding element. mainWindow = null; }); -} +}; -// This method will be called when Electron has finished -// initialization and is ready to create browser windows. -// Some APIs can only be used after this event occurs. app.on('ready', createWindow); -// Quit when all windows are closed. app.on('window-all-closed', () => { - // On OS X it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit(); } }); app.on('activate', () => { - // On OS X it"s common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. if (mainWindow === null) { createWindow(); } }); - -// In this file you can include the rest of your app"s specific main process -// code. You can also put them in separate files and require them here. diff --git a/webpack.common.js b/webpack.common.js index fb38f53..916c217 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -9,7 +9,7 @@ module.exports = { }, output: { path: path.resolve(__dirname, 'dist'), - publicPath: '/' + filename: '[hash].js' }, plugins: [ new ForkTsCheckerWebpackPlugin(), diff --git a/webpack.main.js b/webpack.main.js index 2aa82f3..c3fa3af 100644 --- a/webpack.main.js +++ b/webpack.main.js @@ -2,7 +2,7 @@ const path = require('path'); const webpack = require('webpack'); module.exports = { - mode: 'development', + mode: 'production', devtool: 'inline-source-map', target: 'electron-main', entry: { @@ -19,5 +19,14 @@ module.exports = { loader: 'ts-loader' } ] + }, + plugins: [ + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development') + }) + ], + node: { + __dirname: false, + __filename: false } }; diff --git a/webpack.renderer.prod.js b/webpack.renderer.prod.js new file mode 100644 index 0000000..6b6c0ee --- /dev/null +++ b/webpack.renderer.prod.js @@ -0,0 +1,37 @@ +const path = require('path'); +const merge = require('webpack-merge'); +const webpack = require('webpack'); +const common = require('./webpack.common.js'); +const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); +const WorkboxPlugin = require('workbox-webpack-plugin'); + +module.exports = merge(common, { + mode: 'production', + target: 'electron-renderer', + devtool: 'source-map', + output: { + filename: '[name].[chunkhash].js' + }, + optimization: { + minimize: true, + nodeEnv: 'production', + concatenateModules: true, + splitChunks: { + cacheGroups: { + vendor: { + chunks: 'initial', + name: 'vendors', + test: /[\\/]node_modules[\\/]/, + enforce: true + } + } + }, + runtimeChunk: true + }, + plugins: [ + new WorkboxPlugin.GenerateSW({ + clientsClaim: true, + skipWaiting: true + }) + ] +});