github-desktop/app/webpack.common.ts

199 lines
4.8 KiB
TypeScript
Raw Normal View History

2017-10-28 18:08:07 +00:00
import * as path from 'path'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import webpack from 'webpack'
import merge from 'webpack-merge'
2017-10-28 18:08:07 +00:00
import { getReplacements } from './app-info'
2017-12-24 16:26:38 +00:00
export const externals = ['7zip']
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: {
emitOnErrors: false,
2018-09-14 18:43:59 +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),
library: {
name: '[name]',
type: '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?$/,
include: path.resolve(__dirname, 'src'),
use: [
{
loader: 'ts-loader',
2017-07-13 15:15:34 +00:00
},
],
exclude: /node_modules/,
},
{
2017-04-17 21:23:37 +00:00
test: /\.node$/,
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
},
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
},
}
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'),
})
),
],
})
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: [
{
test: /\.(jpe?g|png|gif|ico)$/,
2017-07-13 15:15:34 +00:00
use: ['file?name=[path][name].[ext]'],
},
{
test: /\.cmd$/,
2023-05-31 12:55:33 +00:00
type: 'asset/resource',
},
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, {
entry: { cli: path.resolve(__dirname, 'src/cli/main') },
2017-06-06 19:29:05 +00:00
target: 'node',
plugins: [
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, {
entry: { highlighter: path.resolve(__dirname, 'src/highlighter/index') },
output: {
library: {
name: '[name]',
type: 'var',
},
chunkFilename: 'highlighter/[name].js',
},
optimization: {
2022-02-14 17:22:25 +00:00
chunkIds: 'named',
splitChunks: {
cacheGroups: {
modes: {
enforce: true,
2022-02-14 17:22:25 +00:00
name: (mod: any) => {
const builtInMode =
/node_modules[\\\/]codemirror[\\\/]mode[\\\/](\w+)[\\\/]/i.exec(
mod.resource
)
if (builtInMode) {
return `mode/${builtInMode[1]}`
}
const external =
/node_modules[\\\/]codemirror-mode-(\w+)[\\\/]/i.exec(
mod.resource
)
if (external) {
return `ext/${external[1]}`
}
return 'common'
},
},
},
},
},
target: 'webworker',
plugins: [
new webpack.DefinePlugin(
Object.assign({}, replacements, {
__PROCESS_KIND__: JSON.stringify('highlighter'),
})
),
],
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',
},
},
})
2018-05-24 00:13:49 +00:00
highlighter.module!.rules = [
{
test: /\.ts$/,
include: path.resolve(__dirname, 'src/highlighter'),
use: [
{
2022-01-28 09:57:12 +00:00
loader: 'ts-loader',
options: {
2022-01-28 09:57:12 +00:00
configFile: path.resolve(__dirname, 'src/highlighter/tsconfig.json'),
},
},
],
exclude: /node_modules/,
},
]