github-desktop/app/webpack.common.js

153 lines
4.4 KiB
JavaScript
Raw Normal View History

2016-05-24 19:12:06 +00:00
'use strict'
const path = require('path')
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
const devClientId = '3a723b10ac5575cc5bb9'
const devClientSecret = '22c34d87789a365981ed921352a7b9a8c3f69d54'
2017-04-18 07:05:02 +00:00
const environment = process.env.NODE_ENV || 'development'
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),
'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?$/,
include: path.resolve(__dirname, 'src'),
use: [
{
loader: 'awesome-typescript-loader',
options: {
useBabel: true,
useCache: true,
},
}
],
exclude: /node_modules/,
},
{
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: [
{
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({
'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: [
new HtmlWebpackPlugin({
'template': path.join(__dirname, 'static', 'error.html'),
// 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' ]
}),
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: [
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-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-04-17 21:47:34 +00:00
replacements: replacements,
externals: commonConfig.externals,
2016-05-24 19:12:06 +00:00
}