2016-05-24 19:12:06 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const path = require('path')
|
2017-06-08 09:30:39 +00:00
|
|
|
const Fs = require('fs')
|
2016-06-16 22:10:31 +00:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
2017-05-01 01:46:42 +00:00
|
|
|
const CleanWebpackPlugin = require('clean-webpack-plugin')
|
2016-10-26 20:37:56 +00:00
|
|
|
const webpack = require('webpack')
|
2017-04-17 20:24:00 +00:00
|
|
|
const merge = require('webpack-merge')
|
2016-05-24 19:12:06 +00:00
|
|
|
|
2017-04-13 13:58:42 +00:00
|
|
|
const devClientId = '3a723b10ac5575cc5bb9'
|
|
|
|
const devClientSecret = '22c34d87789a365981ed921352a7b9a8c3f69d54'
|
|
|
|
|
2017-04-18 07:05:02 +00:00
|
|
|
const environment = process.env.NODE_ENV || 'development'
|
|
|
|
|
2017-06-08 09:30:39 +00:00
|
|
|
/**
|
|
|
|
* Attempt to dereference the given ref without requiring a Git environment
|
|
|
|
* to be present. Note that this method will not be able to dereference packed
|
|
|
|
* refs but should suffice for simple refs like 'HEAD'.
|
|
|
|
*
|
|
|
|
* Will throw an error for unborn HEAD.
|
|
|
|
*
|
|
|
|
* @param {string} gitDir The path to the Git repository's .git directory
|
|
|
|
* @param {string} ref A qualified git ref such as 'HEAD' or 'refs/heads/master'
|
|
|
|
*/
|
|
|
|
function revParse(gitDir, ref) {
|
|
|
|
|
|
|
|
const refPath = path.join(gitDir, ref)
|
|
|
|
const refContents = Fs.readFileSync(refPath)
|
|
|
|
const refRe = /^([a-f0-9]{40})|(?:ref: (refs\/.*))$/m
|
|
|
|
const refMatch = refRe.exec(refContents)
|
|
|
|
|
|
|
|
if (!refMatch) {
|
|
|
|
throw new Error(`Could not de-reference HEAD to SHA, invalid ref in ${refPath}: ${refContents}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
return refMatch[1] || revParse(gitDir, refMatch[2])
|
|
|
|
}
|
|
|
|
|
2017-04-17 21:47:34 +00:00
|
|
|
const replacements = {
|
|
|
|
__OAUTH_CLIENT_ID__: JSON.stringify(process.env.DESKTOP_OAUTH_CLIENT_ID || devClientId),
|
|
|
|
__OAUTH_SECRET__: JSON.stringify(process.env.DESKTOP_OAUTH_CLIENT_SECRET || devClientSecret),
|
|
|
|
__DARWIN__: process.platform === 'darwin',
|
2017-04-18 07:05:02 +00:00
|
|
|
__WIN32__: process.platform === 'win32',
|
|
|
|
__DEV__: environment === 'development',
|
|
|
|
__RELEASE_ENV__: JSON.stringify(environment),
|
2017-06-08 09:30:39 +00:00
|
|
|
__SHA__: JSON.stringify(revParse(path.resolve(__dirname, '../.git'), 'HEAD')),
|
2017-04-18 07:05:02 +00:00
|
|
|
'process.platform': JSON.stringify(process.platform),
|
|
|
|
'process.env.NODE_ENV': JSON.stringify(environment),
|
|
|
|
'process.env.TEST_ENV': JSON.stringify(process.env.TEST_ENV),
|
2017-04-17 21:47:34 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 01:46:42 +00:00
|
|
|
const outputDir = 'out'
|
|
|
|
|
2017-04-17 20:24:00 +00:00
|
|
|
const commonConfig = {
|
2017-04-27 20:16:12 +00:00
|
|
|
externals: [ '7zip' ],
|
2016-05-24 19:12:06 +00:00
|
|
|
output: {
|
2016-06-24 13:52:24 +00:00
|
|
|
filename: '[name].js',
|
2017-05-01 01:46:42 +00:00
|
|
|
path: path.resolve(__dirname, '..', outputDir),
|
2016-05-24 19:12:06 +00:00
|
|
|
libraryTarget: 'commonjs2'
|
|
|
|
},
|
|
|
|
module: {
|
2017-04-17 21:23:37 +00:00
|
|
|
rules: [
|
2016-05-24 19:12:06 +00:00
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
2017-04-18 04:04:20 +00:00
|
|
|
include: path.resolve(__dirname, 'src'),
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'awesome-typescript-loader',
|
|
|
|
options: {
|
|
|
|
useBabel: true,
|
|
|
|
useCache: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
],
|
|
|
|
exclude: /node_modules/,
|
2016-06-16 17:23:52 +00:00
|
|
|
},
|
2016-06-16 23:37:57 +00:00
|
|
|
{
|
2017-04-17 21:23:37 +00:00
|
|
|
test: /\.node$/,
|
|
|
|
use: [
|
|
|
|
{ loader: 'node-native-loader', options: { name: "[name].[ext]" } }
|
|
|
|
],
|
2016-05-24 19:12:06 +00:00
|
|
|
}
|
2017-04-17 21:23:37 +00:00
|
|
|
],
|
2016-05-24 19:12:06 +00:00
|
|
|
},
|
2017-04-17 20:24:00 +00:00
|
|
|
plugins: [
|
2017-05-01 01:50:07 +00:00
|
|
|
new CleanWebpackPlugin([ outputDir ], { verbose: false }),
|
2017-04-18 07:04:27 +00:00
|
|
|
// This saves us a bunch of bytes by pruning locales (which we don't use)
|
|
|
|
// from moment.
|
|
|
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
2017-04-17 21:47:34 +00:00
|
|
|
new webpack.NoEmitOnErrorsPlugin(),
|
2017-04-17 20:24:00 +00:00
|
|
|
],
|
2016-05-24 19:12:06 +00:00
|
|
|
resolve: {
|
2017-04-17 20:24:00 +00:00
|
|
|
extensions: [ '.js', '.ts', '.tsx' ],
|
|
|
|
modules: [ path.resolve(__dirname, 'node_modules/') ],
|
|
|
|
},
|
|
|
|
node: {
|
|
|
|
__dirname: false,
|
|
|
|
__filename: false
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const mainConfig = merge({}, commonConfig, {
|
|
|
|
entry: { main: path.resolve(__dirname, 'src/main-process/main') },
|
|
|
|
target: 'electron-main',
|
2017-05-31 15:10:38 +00:00
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin(Object.assign({ }, replacements, { '__PROCESS_KIND__': JSON.stringify('main') })),
|
|
|
|
]
|
2017-04-17 20:24:00 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const rendererConfig = merge({}, commonConfig, {
|
|
|
|
entry: { renderer: path.resolve(__dirname, 'src/ui/index') },
|
|
|
|
target: 'electron-renderer',
|
2016-05-24 19:12:06 +00:00
|
|
|
module: {
|
2017-04-17 20:24:00 +00:00
|
|
|
rules: [
|
2016-06-16 23:37:57 +00:00
|
|
|
{
|
|
|
|
test: /\.(jpe?g|png|gif|ico)$/,
|
2017-04-17 20:24:00 +00:00
|
|
|
use: ['file?name=[path][name].[ext]']
|
2016-05-24 19:12:06 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2016-06-24 13:52:24 +00:00
|
|
|
plugins: [
|
|
|
|
new HtmlWebpackPlugin({
|
2016-07-21 18:31:30 +00:00
|
|
|
'template': path.join(__dirname, 'static', 'index.html'),
|
2016-06-24 13:52:24 +00:00
|
|
|
'chunks': ['renderer']
|
|
|
|
}),
|
2017-05-31 15:10:38 +00:00
|
|
|
new webpack.DefinePlugin(Object.assign({ }, replacements, { '__PROCESS_KIND__': JSON.stringify('ui') })),
|
2017-04-17 20:24:00 +00:00
|
|
|
],
|
|
|
|
})
|
|
|
|
|
|
|
|
const sharedConfig = merge({}, commonConfig, {
|
|
|
|
entry: { shared: path.resolve(__dirname, 'src/shared-process/index') },
|
|
|
|
target: 'electron-renderer',
|
|
|
|
plugins: [
|
2017-04-19 02:41:57 +00:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
'template': path.join(__dirname, 'static', 'error.html'),
|
2017-04-19 06:56:16 +00:00
|
|
|
// without this we overwrite index.html
|
|
|
|
'filename': 'error.html',
|
|
|
|
// we don't need any scripts to run on this page
|
|
|
|
'excludeChunks': [ 'main', 'renderer', 'shared', 'ask-pass' ]
|
2017-04-19 02:41:57 +00:00
|
|
|
}),
|
2016-06-24 13:52:24 +00:00
|
|
|
new HtmlWebpackPlugin({
|
2016-06-24 15:48:43 +00:00
|
|
|
'filename': 'shared.html',
|
|
|
|
'chunks': ['shared']
|
2016-10-26 20:37:56 +00:00
|
|
|
}),
|
2017-05-31 15:10:38 +00:00
|
|
|
new webpack.DefinePlugin(Object.assign({ }, replacements, { '__PROCESS_KIND__': JSON.stringify('shared') })),
|
2016-06-24 13:52:24 +00:00
|
|
|
],
|
2017-04-17 20:24:00 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const askPassConfig = merge({}, commonConfig, {
|
|
|
|
entry: { 'ask-pass': path.resolve(__dirname, 'src/ask-pass/main') },
|
|
|
|
target: 'node',
|
2017-05-31 15:10:38 +00:00
|
|
|
plugins: [
|
2017-06-06 19:29:05 +00:00
|
|
|
new webpack.DefinePlugin(Object.assign({ }, replacements, { '__PROCESS_KIND__': JSON.stringify('askpass') })),
|
2017-05-31 15:10:38 +00:00
|
|
|
]
|
2017-04-17 20:24:00 +00:00
|
|
|
})
|
|
|
|
|
2017-05-22 07:20:49 +00:00
|
|
|
const crashConfig = merge({}, commonConfig, {
|
2017-05-22 07:59:18 +00:00
|
|
|
entry: { crash: path.resolve(__dirname, 'src/crash/index') },
|
2017-05-22 07:20:49 +00:00
|
|
|
target: 'electron-renderer',
|
|
|
|
plugins: [
|
|
|
|
new HtmlWebpackPlugin({
|
2017-05-22 07:59:26 +00:00
|
|
|
title: 'GitHub Desktop',
|
|
|
|
filename: 'crash.html',
|
|
|
|
chunks: ['crash']
|
2017-05-22 07:20:49 +00:00
|
|
|
}),
|
2017-05-31 15:10:38 +00:00
|
|
|
new webpack.DefinePlugin(Object.assign({ }, replacements, { '__PROCESS_KIND__': JSON.stringify('crash') })),
|
2017-05-22 07:20:49 +00:00
|
|
|
],
|
|
|
|
})
|
|
|
|
|
2017-06-06 19:29:05 +00:00
|
|
|
const cliConfig = merge({}, commonConfig, {
|
|
|
|
entry: { 'cli': path.resolve(__dirname, 'src/cli/main') },
|
|
|
|
target: 'node',
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin(Object.assign({ }, replacements, { '__PROCESS_KIND__': JSON.stringify('cli') })),
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2017-04-17 20:24:00 +00:00
|
|
|
module.exports = {
|
|
|
|
main: mainConfig,
|
|
|
|
shared: sharedConfig,
|
|
|
|
renderer: rendererConfig,
|
|
|
|
askPass: askPassConfig,
|
2017-05-22 07:20:49 +00:00
|
|
|
crash: crashConfig,
|
2017-06-06 19:29:05 +00:00
|
|
|
cli: cliConfig,
|
2017-04-17 21:47:34 +00:00
|
|
|
replacements: replacements,
|
|
|
|
externals: commonConfig.externals,
|
2016-05-24 19:12:06 +00:00
|
|
|
}
|