2017-10-28 18:08:07 +00:00
|
|
|
import * as path from 'path'
|
2020-07-08 08:41:20 +00:00
|
|
|
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
|
|
import webpack from 'webpack'
|
|
|
|
import merge from 'webpack-merge'
|
2019-11-04 18:41:06 +00:00
|
|
|
import { getChannel } from '../script/dist-info'
|
2017-10-28 18:08:07 +00:00
|
|
|
import { getReplacements } from './app-info'
|
|
|
|
|
2019-11-04 18:41:06 +00:00
|
|
|
const channel = getChannel()
|
2017-04-18 07:05:02 +00:00
|
|
|
|
2017-12-24 16:26:38 +00:00
|
|
|
export 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'
|
2017-12-24 16:26:38 +00:00
|
|
|
export const replacements = getReplacements()
|
2017-11-20 01:39:32 +00:00
|
|
|
|
2017-10-28 18:08:07 +00:00
|
|
|
const commonConfig: webpack.Configuration = {
|
2018-09-14 18:43:59 +00:00
|
|
|
optimization: {
|
|
|
|
noEmitOnErrors: true,
|
|
|
|
},
|
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',
|
2022-02-14 17:22:25 +00:00
|
|
|
clean: true,
|
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: [
|
|
|
|
{
|
2022-01-28 09:30:48 +00:00
|
|
|
loader: 'ts-loader',
|
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$/,
|
2018-05-04 06:15:22 +00:00
|
|
|
loader: 'awesome-node-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]',
|
|
|
|
},
|
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-04-18 07:04:27 +00:00
|
|
|
// This saves us a bunch of bytes by pruning locales (which we don't use)
|
|
|
|
// from moment.
|
2022-02-14 17:22:25 +00:00
|
|
|
new webpack.IgnorePlugin({
|
|
|
|
resourceRegExp: /^\.\/locale$/,
|
|
|
|
contextRegExp: /moment$/,
|
|
|
|
}),
|
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'],
|
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
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-07-09 10:27:17 +00:00
|
|
|
// Hack: The file-metadata plugin has substantial dependencies
|
|
|
|
// (plist, DOMParser, etc) and it's only applicable on macOS.
|
|
|
|
//
|
|
|
|
// Therefore, when compiling on other platforms, we replace it
|
|
|
|
// with a tiny shim instead.
|
|
|
|
const shimFileMetadata = {
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'file-metadata': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'src',
|
|
|
|
'lib',
|
|
|
|
'helpers',
|
|
|
|
'file-metadata.js'
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export const main = merge(
|
|
|
|
{},
|
|
|
|
commonConfig,
|
|
|
|
{
|
|
|
|
entry: { main: path.resolve(__dirname, 'src/main-process/main') },
|
|
|
|
target: 'electron-main',
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin(
|
|
|
|
Object.assign({}, replacements, {
|
|
|
|
__PROCESS_KIND__: JSON.stringify('main'),
|
|
|
|
})
|
|
|
|
),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
process.platform !== 'darwin' ? shimFileMetadata : {}
|
|
|
|
)
|
2017-04-17 20:24:00 +00:00
|
|
|
|
2017-12-24 16:26:38 +00:00
|
|
|
export const renderer = merge({}, commonConfig, {
|
2017-04-17 20:24:00 +00:00
|
|
|
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]'],
|
|
|
|
},
|
2018-12-17 18:32:51 +00:00
|
|
|
{
|
|
|
|
test: /\.cmd$/,
|
|
|
|
loader: 'file-loader',
|
|
|
|
},
|
2017-07-13 15:15:34 +00:00
|
|
|
],
|
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
|
|
|
],
|
|
|
|
})
|
|
|
|
|
2017-12-24 16:26:38 +00:00
|
|
|
export const crash = 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-12-24 16:26:38 +00:00
|
|
|
export const cli = 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-12-24 16:26:38 +00:00
|
|
|
export const highlighter = merge({}, commonConfig, {
|
2017-10-14 19:26:52 +00:00
|
|
|
entry: { highlighter: path.resolve(__dirname, 'src/highlighter/index') },
|
2018-05-22 13:47:11 +00:00
|
|
|
output: {
|
|
|
|
libraryTarget: 'var',
|
|
|
|
chunkFilename: 'highlighter/[name].js',
|
|
|
|
},
|
|
|
|
optimization: {
|
2022-02-14 17:22:25 +00:00
|
|
|
chunkIds: 'named',
|
2018-05-22 13:47:11 +00:00
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
modes: {
|
|
|
|
enforce: true,
|
2022-02-14 17:22:25 +00:00
|
|
|
name: (mod: any) => {
|
2019-09-23 14:43:37 +00:00
|
|
|
const builtInMode = /node_modules[\\\/]codemirror[\\\/]mode[\\\/](\w+)[\\\/]/i.exec(
|
2018-05-22 13:47:11 +00:00
|
|
|
mod.resource
|
|
|
|
)
|
|
|
|
if (builtInMode) {
|
|
|
|
return `mode/${builtInMode[1]}`
|
|
|
|
}
|
2019-09-23 14:43:37 +00:00
|
|
|
const external = /node_modules[\\\/]codemirror-mode-(\w+)[\\\/]/i.exec(
|
2018-05-22 13:47:11 +00:00
|
|
|
mod.resource
|
|
|
|
)
|
|
|
|
if (external) {
|
|
|
|
return `ext/${external[1]}`
|
|
|
|
}
|
|
|
|
return 'common'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-10-14 19:26:52 +00:00
|
|
|
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
|
|
|
})
|
2018-05-24 00:13:49 +00:00
|
|
|
|
|
|
|
highlighter.module!.rules = [
|
2017-10-14 19:26:52 +00:00
|
|
|
{
|
|
|
|
test: /\.ts$/,
|
|
|
|
include: path.resolve(__dirname, 'src/highlighter'),
|
|
|
|
use: [
|
|
|
|
{
|
2022-01-28 09:57:12 +00:00
|
|
|
loader: 'ts-loader',
|
2017-10-14 19:26:52 +00:00
|
|
|
options: {
|
2022-01-28 09:57:12 +00:00
|
|
|
configFile: path.resolve(__dirname, 'src/highlighter/tsconfig.json'),
|
2017-10-14 19:26:52 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
|
|
|
]
|