github-desktop/app/webpack.common.ts

226 lines
5.7 KiB
TypeScript
Raw Normal View History

2017-10-28 18:08:07 +00:00
import * as path from 'path'
import * as HtmlWebpackPlugin from 'html-webpack-plugin'
import * as CleanWebpackPlugin from 'clean-webpack-plugin'
import * as webpack from 'webpack'
import * as merge from 'webpack-merge'
import { getChannel } from '../script/dist-info'
2017-10-28 18:08:07 +00:00
import { getReplacements } from './app-info'
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') {
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,
},
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?$/,
include: path.resolve(__dirname, 'src'),
use: [
{
loader: 'awesome-typescript-loader',
options: {
useBabel: true,
useCache: true,
},
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
},
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 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
},
}
2017-12-24 16:26:38 +00:00
export const main = merge({}, commonConfig, {
2017-04-17 20:24:00 +00:00
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
})
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$/,
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 askPass = merge({}, commonConfig, {
2017-04-17 20:24:00 +00:00
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-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: {
libraryTarget: 'var',
chunkFilename: 'highlighter/[name].js',
},
optimization: {
namedChunks: true,
splitChunks: {
cacheGroups: {
modes: {
enforce: true,
name: (mod, chunks) => {
2019-09-23 14:43:37 +00:00
const builtInMode = /node_modules[\\\/]codemirror[\\\/]mode[\\\/](\w+)[\\\/]/i.exec(
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(
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: [
{
loader: 'awesome-typescript-loader',
options: {
useBabel: true,
useCache: true,
configFileName: path.resolve(
__dirname,
'src/highlighter/tsconfig.json'
),
},
},
],
exclude: /node_modules/,
},
]