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')
|
2017-11-20 01:30:16 +00:00
|
|
|
const appInfo = require('./app-info')
|
|
|
|
const packageInfo = require('./package-info')
|
2017-07-13 15:02:19 +00:00
|
|
|
const distInfo = require('../script/dist-info')
|
2016-05-24 19:12:06 +00:00
|
|
|
|
2017-07-13 14:29:08 +00:00
|
|
|
const channel = distInfo.getReleaseChannel()
|
2017-04-18 07:05:02 +00:00
|
|
|
|
2017-07-20 00:54:22 +00:00
|
|
|
const externals = ['7zip']
|
2017-07-20 18:47:04 +00:00
|
|
|
if (channel === 'development') {
|
2017-07-20 00:54:22 +00:00
|
|
|
externals.push('devtron')
|
|
|
|
}
|
|
|
|
|
2017-11-20 01:39:32 +00:00
|
|
|
const outputDir = 'out'
|
|
|
|
const replacements = appInfo.getReplacements()
|
|
|
|
|
2017-04-17 20:24:00 +00:00
|
|
|
const commonConfig = {
|
2017-07-20 00:54:22 +00:00
|
|
|
externals: externals,
|
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),
|
2017-07-13 15:15:34 +00:00
|
|
|
libraryTarget: 'commonjs2',
|
2016-05-24 19:12:06 +00:00
|
|
|
},
|
|
|
|
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,
|
|
|
|
},
|
2017-07-13 15:15:34 +00:00
|
|
|
},
|
2017-04-18 04:04:20 +00:00
|
|
|
],
|
|
|
|
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: [
|
2017-07-13 15:15:34 +00:00
|
|
|
{ loader: 'node-native-loader', options: { name: '[name].[ext]' } },
|
2017-04-17 21:23:37 +00:00
|
|
|
],
|
2017-07-13 15:15:34 +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-07-13 15:15:34 +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-07-13 15:15:34 +00:00
|
|
|
extensions: ['.js', '.ts', '.tsx'],
|
|
|
|
modules: [path.resolve(__dirname, 'node_modules/')],
|
2017-04-17 20:24:00 +00:00
|
|
|
},
|
|
|
|
node: {
|
|
|
|
__dirname: false,
|
2017-07-13 15:15:34 +00:00
|
|
|
__filename: false,
|
2017-04-17 20:24:00 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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: [
|
2017-07-13 15:15:34 +00:00
|
|
|
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-07-13 15:15:34 +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({
|
2017-07-13 15:15:34 +00:00
|
|
|
template: path.join(__dirname, 'static', 'index.html'),
|
|
|
|
chunks: ['renderer'],
|
2016-06-24 13:52:24 +00:00
|
|
|
}),
|
2017-07-13 15:15:34 +00:00
|
|
|
new webpack.DefinePlugin(
|
|
|
|
Object.assign({}, replacements, {
|
|
|
|
__PROCESS_KIND__: JSON.stringify('ui'),
|
|
|
|
})
|
|
|
|
),
|
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-07-13 15:15:34 +00:00
|
|
|
new webpack.DefinePlugin(
|
|
|
|
Object.assign({}, replacements, {
|
|
|
|
__PROCESS_KIND__: JSON.stringify('askpass'),
|
|
|
|
})
|
|
|
|
),
|
|
|
|
],
|
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',
|
2017-07-13 15:15:34 +00:00
|
|
|
chunks: ['crash'],
|
2017-05-22 07:20:49 +00:00
|
|
|
}),
|
2017-07-13 15:15:34 +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, {
|
2017-07-13 19:46:45 +00:00
|
|
|
entry: { cli: path.resolve(__dirname, 'src/cli/main') },
|
2017-06-06 19:29:05 +00:00
|
|
|
target: 'node',
|
|
|
|
plugins: [
|
2017-07-13 19:46:45 +00:00
|
|
|
new webpack.DefinePlugin(
|
|
|
|
Object.assign({}, replacements, {
|
|
|
|
__PROCESS_KIND__: JSON.stringify('cli'),
|
|
|
|
})
|
|
|
|
),
|
2017-05-22 07:20:49 +00:00
|
|
|
],
|
|
|
|
})
|
|
|
|
|
2017-10-14 19:26:52 +00:00
|
|
|
const highlighterConfig = merge({}, commonConfig, {
|
|
|
|
entry: { highlighter: path.resolve(__dirname, 'src/highlighter/index') },
|
|
|
|
output: { libraryTarget: 'var' },
|
|
|
|
target: 'webworker',
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin(
|
|
|
|
Object.assign({}, replacements, {
|
|
|
|
__PROCESS_KIND__: JSON.stringify('highlighter'),
|
|
|
|
})
|
|
|
|
),
|
|
|
|
],
|
2017-10-16 15:12:24 +00:00
|
|
|
resolve: {
|
|
|
|
// We don't want to bundle all of CodeMirror in the highlighter. A web
|
|
|
|
// worker doesn't have access to the DOM and most of CodeMirror's core
|
|
|
|
// code is useless to us in that context. So instead we use this super
|
|
|
|
// nifty subset of codemirror that defines the minimal context needed
|
|
|
|
// to run a mode inside of node. Now, we're not running in node
|
|
|
|
// but CodeMirror doesn't have to know about that.
|
|
|
|
alias: {
|
|
|
|
codemirror$: 'codemirror/addon/runmode/runmode.node.js',
|
|
|
|
'../lib/codemirror$': '../addon/runmode/runmode.node.js',
|
|
|
|
'../../lib/codemirror$': '../../addon/runmode/runmode.node.js',
|
|
|
|
'../../addon/runmode/runmode$': '../../addon/runmode/runmode.node.js',
|
|
|
|
},
|
|
|
|
},
|
2017-10-14 19:26:52 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
highlighterConfig.module.rules = [
|
|
|
|
{
|
|
|
|
test: /\.ts$/,
|
|
|
|
include: path.resolve(__dirname, 'src/highlighter'),
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'awesome-typescript-loader',
|
|
|
|
options: {
|
|
|
|
useBabel: true,
|
|
|
|
useCache: true,
|
2017-10-18 09:26:23 +00:00
|
|
|
configFileName: path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'src/highlighter/tsconfig.json'
|
|
|
|
),
|
2017-10-14 19:26:52 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2017-04-17 20:24:00 +00:00
|
|
|
module.exports = {
|
|
|
|
main: mainConfig,
|
|
|
|
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-10-14 19:26:52 +00:00
|
|
|
highlighter: highlighterConfig,
|
2017-04-17 21:47:34 +00:00
|
|
|
replacements: replacements,
|
|
|
|
externals: commonConfig.externals,
|
2016-05-24 19:12:06 +00:00
|
|
|
}
|