From 1f24033b981b4e9c642a6c464b124af30fea3f16 Mon Sep 17 00:00:00 2001 From: richard-loafle <44828666+richard-loafle@users.noreply.github.com> Date: Fri, 27 Mar 2020 18:04:12 +0900 Subject: [PATCH] environment is added --- config/enviroment.js | 15 +++ config/webpack.config.js | 17 ++- package-lock.json | 253 +++++++++++++++++++++++++++++++++++++++ package.json | 2 + src/global.d.ts | 12 ++ 5 files changed, 295 insertions(+), 4 deletions(-) create mode 100644 config/enviroment.js create mode 100644 src/global.d.ts diff --git a/config/enviroment.js b/config/enviroment.js new file mode 100644 index 0000000..bb43330 --- /dev/null +++ b/config/enviroment.js @@ -0,0 +1,15 @@ +const channel = process.env.NODE_ENV; + +const s = JSON.stringify; + +module.exports = function() { + return { + __DARWIN__: process.platform === 'darwin', + __WIN32__: process.platform === 'win32', + __LINUX__: process.platform === 'linux', + __DEV__: channel === 'development', + 'process.platform': s(process.platform), + 'process.env.NODE_ENV': s(process.env.NODE_ENV || 'development'), + 'process.env.TEST_ENV': s(process.env.TEST_ENV) + }; +}; diff --git a/config/webpack.config.js b/config/webpack.config.js index 0a0841f..d4ec163 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -1,12 +1,21 @@ const path = require('path'); +const webpack = require('webpack'); const webpackNodeExternals = require('webpack-node-externals'); +const { CleanWebpackPlugin } = require('clean-webpack-plugin'); + +const getEnviroment = require('./enviroment'); const rootPath = path.join(__dirname, '..'); +const enviroment = getEnviroment(); module.exports = [ { mode: process.env.ENV || 'development', entry: path.join(rootPath, 'src', 'main'), + output: { + path: path.join(rootPath, 'dist'), + filename: 'electron-main.js' + }, target: 'electron-main', devtool: 'source-map', externals: [webpackNodeExternals()], @@ -29,9 +38,9 @@ module.exports = [ } ] }, - output: { - path: path.join(rootPath, 'dist'), - filename: 'electron-main.js' - } + plugins: [ + new CleanWebpackPlugin({ verbose: false }), + new webpack.DefinePlugin(Object.assign({}, enviroment, {})) + ] } ]; diff --git a/package-lock.json b/package-lock.json index 8c1b9a2..db0da33 100644 --- a/package-lock.json +++ b/package-lock.json @@ -278,6 +278,12 @@ "tslib": "1.11.1" } }, + "@types/anymatch": { + "version": "1.3.1", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/anymatch/-/anymatch-1.3.1.tgz", + "integrity": "sha512-/+CRPXpBDpo2RK9C68N3b2cOvO0Cf5B9aPijHsoDQTHivnGSObdOF2BRQOYjojWTDy6nQvMjmqRXIxH55VjxxA==", + "dev": true + }, "@types/color-name": { "version": "1.1.1", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/color-name/-/color-name-1.1.1.tgz", @@ -289,6 +295,12 @@ "integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==", "dev": true }, + "@types/events": { + "version": "3.0.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/events/-/events-3.0.0.tgz", + "integrity": "sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==", + "dev": true + }, "@types/fs-extra": { "version": "8.1.0", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/fs-extra/-/fs-extra-8.1.0.tgz", @@ -298,6 +310,17 @@ "@types/node": "*" } }, + "@types/glob": { + "version": "7.1.1", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/glob/-/glob-7.1.1.tgz", + "integrity": "sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==", + "dev": true, + "requires": { + "@types/events": "*", + "@types/minimatch": "*", + "@types/node": "*" + } + }, "@types/jasmine": { "version": "3.5.10", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/jasmine/-/jasmine-3.5.10.tgz", @@ -313,6 +336,12 @@ "@types/jasmine": "*" } }, + "@types/minimatch": { + "version": "3.0.3", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/minimatch/-/minimatch-3.0.3.tgz", + "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==", + "dev": true + }, "@types/node": { "version": "12.12.31", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/node/-/node-12.12.31.tgz", @@ -338,6 +367,52 @@ "@types/node": "*" } }, + "@types/source-list-map": { + "version": "0.1.2", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/source-list-map/-/source-list-map-0.1.2.tgz", + "integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==", + "dev": true + }, + "@types/tapable": { + "version": "1.0.5", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/tapable/-/tapable-1.0.5.tgz", + "integrity": "sha512-/gG2M/Imw7cQFp8PGvz/SwocNrmKFjFsm5Pb8HdbHkZ1K8pmuPzOX4VeVoiEecFCVf4CsN1r3/BRvx+6sNqwtQ==", + "dev": true + }, + "@types/uglify-js": { + "version": "3.0.4", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/uglify-js/-/uglify-js-3.0.4.tgz", + "integrity": "sha512-SudIN9TRJ+v8g5pTG8RRCqfqTMNqgWCKKd3vtynhGzkIIjxaicNAMuY5TRadJ6tzDu3Dotf3ngaMILtmOdmWEQ==", + "dev": true, + "requires": { + "source-map": "^0.6.1" + } + }, + "@types/webpack": { + "version": "4.41.8", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/webpack/-/webpack-4.41.8.tgz", + "integrity": "sha512-mh4litLHTlDG84TGCFv1pZldndI34vkrW9Mks++Zx4KET7DRMoCXUvLbTISiuF4++fMgNnhV9cc1nCXJQyBYbQ==", + "dev": true, + "requires": { + "@types/anymatch": "*", + "@types/node": "*", + "@types/tapable": "*", + "@types/uglify-js": "*", + "@types/webpack-sources": "*", + "source-map": "^0.6.0" + } + }, + "@types/webpack-sources": { + "version": "0.1.7", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/webpack-sources/-/webpack-sources-0.1.7.tgz", + "integrity": "sha512-XyaHrJILjK1VHVC4aVlKsdNN5KBTwufMb43cQs+flGxtPAf/1Qwl8+Q0tp5BwEGaI8D6XT1L+9bSWXckgkjTLw==", + "dev": true, + "requires": { + "@types/node": "*", + "@types/source-list-map": "*", + "source-map": "^0.6.1" + } + }, "@types/yargs": { "version": "15.0.4", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@types/yargs/-/yargs-15.0.4.tgz", @@ -633,6 +708,12 @@ } } }, + "ansi-colors": { + "version": "3.2.4", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/ansi-colors/-/ansi-colors-3.2.4.tgz", + "integrity": "sha512-hHUXGagefjN2iRrID63xckIvotOXOojhQKWIPUZ4mNUZ9nLZW+7FMNoE1lOkEhNWYsx/7ysGIuJYCiMAA9FnrA==", + "dev": true + }, "ansi-regex": { "version": "4.1.0", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/ansi-regex/-/ansi-regex-4.1.0.tgz", @@ -1535,6 +1616,84 @@ } } }, + "clean-webpack-plugin": { + "version": "3.0.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/clean-webpack-plugin/-/clean-webpack-plugin-3.0.0.tgz", + "integrity": "sha512-MciirUH5r+cYLGCOL5JX/ZLzOZbVr1ot3Fw+KcvbhUb6PM+yycqd9ZhIlcigQ5gl+XhppNmw3bEFuaaMNyLj3A==", + "dev": true, + "requires": { + "@types/webpack": "^4.4.31", + "del": "^4.1.1" + }, + "dependencies": { + "del": { + "version": "4.1.1", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/del/-/del-4.1.1.tgz", + "integrity": "sha512-QwGuEUouP2kVwQenAsOof5Fv8K9t3D8Ca8NxcXKrIpEHjTXK5J2nXLdP+ALI1cgv8wj7KuwBhTwBkOZSJKM5XQ==", + "dev": true, + "requires": { + "@types/glob": "^7.1.1", + "globby": "^6.1.0", + "is-path-cwd": "^2.0.0", + "is-path-in-cwd": "^2.0.0", + "p-map": "^2.0.0", + "pify": "^4.0.1", + "rimraf": "^2.6.3" + } + }, + "globby": { + "version": "6.1.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/globby/-/globby-6.1.0.tgz", + "integrity": "sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=", + "dev": true, + "requires": { + "array-union": "^1.0.1", + "glob": "^7.0.3", + "object-assign": "^4.0.1", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0" + }, + "dependencies": { + "pify": { + "version": "2.3.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true + } + } + }, + "is-path-cwd": { + "version": "2.2.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/is-path-cwd/-/is-path-cwd-2.2.0.tgz", + "integrity": "sha512-w942bTcih8fdJPJmQHFzkS76NEP8Kzzvmw92cXsazb8intwLqPibPPdXf4ANdKV3rYMuuQYGIWtvz9JilB3NFQ==", + "dev": true + }, + "is-path-in-cwd": { + "version": "2.1.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/is-path-in-cwd/-/is-path-in-cwd-2.1.0.tgz", + "integrity": "sha512-rNocXHgipO+rvnP6dk3zI20RpOtrAM/kzbB258Uw5BWr3TpXi861yzjo16Dn4hUox07iw5AyeMLHWsujkjzvRQ==", + "dev": true, + "requires": { + "is-path-inside": "^2.1.0" + } + }, + "is-path-inside": { + "version": "2.1.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/is-path-inside/-/is-path-inside-2.1.0.tgz", + "integrity": "sha512-wiyhTzfDWsvwAW53OBWF5zuvaOGlZ6PwYxAbPVDhpm+gM09xKQGjBq/8uYN12aDvMxnAnq3dxTyoSoRNmg5YFg==", + "dev": true, + "requires": { + "path-is-inside": "^1.0.2" + } + }, + "pify": { + "version": "4.0.1", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/pify/-/pify-4.0.1.tgz", + "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==", + "dev": true + } + } + }, "cli-boxes": { "version": "2.2.0", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/cli-boxes/-/cli-boxes-2.2.0.tgz", @@ -1791,6 +1950,63 @@ "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=", "dev": true }, + "copy-webpack-plugin": { + "version": "5.1.1", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/copy-webpack-plugin/-/copy-webpack-plugin-5.1.1.tgz", + "integrity": "sha512-P15M5ZC8dyCjQHWwd4Ia/dm0SgVvZJMYeykVIVYXbGyqO4dWB5oyPHp9i7wjwo5LhtlhKbiBCdS2NvM07Wlybg==", + "dev": true, + "requires": { + "cacache": "^12.0.3", + "find-cache-dir": "^2.1.0", + "glob-parent": "^3.1.0", + "globby": "^7.1.1", + "is-glob": "^4.0.1", + "loader-utils": "^1.2.3", + "minimatch": "^3.0.4", + "normalize-path": "^3.0.0", + "p-limit": "^2.2.1", + "schema-utils": "^1.0.0", + "serialize-javascript": "^2.1.2", + "webpack-log": "^2.0.0" + }, + "dependencies": { + "glob-parent": { + "version": "3.1.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/glob-parent/-/glob-parent-3.1.0.tgz", + "integrity": "sha1-nmr2KZ2NO9K9QEMIMr0RPfkGxa4=", + "dev": true, + "requires": { + "is-glob": "^3.1.0", + "path-dirname": "^1.0.0" + }, + "dependencies": { + "is-glob": { + "version": "3.1.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/is-glob/-/is-glob-3.1.0.tgz", + "integrity": "sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo=", + "dev": true, + "requires": { + "is-extglob": "^2.1.0" + } + } + } + }, + "globby": { + "version": "7.1.1", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/globby/-/globby-7.1.1.tgz", + "integrity": "sha1-+yzP+UAfhgCUXfral0QMypcrhoA=", + "dev": true, + "requires": { + "array-union": "^1.0.1", + "dir-glob": "^2.0.0", + "glob": "^7.1.2", + "ignore": "^3.3.5", + "pify": "^3.0.0", + "slash": "^1.0.0" + } + } + } + }, "core-js": { "version": "3.6.4", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/core-js/-/core-js-3.6.4.tgz", @@ -2118,6 +2334,15 @@ "randombytes": "^2.0.0" } }, + "dir-glob": { + "version": "2.2.2", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/dir-glob/-/dir-glob-2.2.2.tgz", + "integrity": "sha512-f9LBi5QWzIW3I6e//uxZoLBlUt9kcp66qo0sSCxL6YZKc75R1c4MFCoe/LaZiBGmgujvQdxc5Bn3QhfyvK5Hsw==", + "dev": true, + "requires": { + "path-type": "^3.0.0" + } + }, "dmg-builder": { "version": "22.4.1", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/dmg-builder/-/dmg-builder-22.4.1.tgz", @@ -3840,6 +4065,12 @@ "integrity": "sha1-xg7taebY/bazEEofy8ocGS3FtQE=", "dev": true }, + "ignore": { + "version": "3.3.10", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/ignore/-/ignore-3.3.10.tgz", + "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==", + "dev": true + }, "immediate": { "version": "3.0.6", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/immediate/-/immediate-3.0.6.tgz", @@ -5457,6 +5688,12 @@ "p-limit": "^2.0.0" } }, + "p-map": { + "version": "2.1.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/p-map/-/p-map-2.1.0.tgz", + "integrity": "sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw==", + "dev": true + }, "p-try": { "version": "2.2.0", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/p-try/-/p-try-2.2.0.tgz", @@ -6526,6 +6763,12 @@ "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/signal-exit/-/signal-exit-3.0.3.tgz", "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==" }, + "slash": { + "version": "1.0.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/slash/-/slash-1.0.0.tgz", + "integrity": "sha1-xB8vbDn8FtHNF61LXYlhFK5HDVU=", + "dev": true + }, "snapdragon": { "version": "0.8.2", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/snapdragon/-/snapdragon-0.8.2.tgz", @@ -8995,6 +9238,16 @@ } } }, + "webpack-log": { + "version": "2.0.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/webpack-log/-/webpack-log-2.0.0.tgz", + "integrity": "sha512-cX8G2vR/85UYG59FgkoMamwHUIkSSlV3bBMRsbxVXVUk2j6NleCKjQ/WE9eYg9WY4w25O9w8wKP4rzNZFmUcUg==", + "dev": true, + "requires": { + "ansi-colors": "^3.0.0", + "uuid": "^3.3.2" + } + }, "webpack-merge": { "version": "4.2.2", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/webpack-merge/-/webpack-merge-4.2.2.tgz", diff --git a/package.json b/package.json index 1f6de89..cc6c6f0 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "@types/node": "^12.11.1", "@types/jasmine": "~3.5.0", "@types/jasminewd2": "~2.0.3", + "clean-webpack-plugin": "^3.0.0", + "copy-webpack-plugin": "^5.1.1", "cross-env": "^7.0.2", "devtron": "^1.4.0", "electron": "^8.1.1", diff --git a/src/global.d.ts b/src/global.d.ts new file mode 100644 index 0000000..e513e63 --- /dev/null +++ b/src/global.d.ts @@ -0,0 +1,12 @@ +/* eslint-disable @typescript-eslint/interface-name-prefix */ +/** Is the app running in dev mode? */ +declare const __DEV__: boolean; + +/** Is the app being built to run on Darwin? */ +declare const __DARWIN__: boolean; + +/** Is the app being built to run on Win32? */ +declare const __WIN32__: boolean; + +/** Is the app being built to run on Linux? */ +declare const __LINUX__: boolean;