github-desktop/app/webpack.common.js

209 lines
5.2 KiB
JavaScript
Raw Normal View History

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')
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')
const distInfo = require('../script/dist-info')
2016-05-24 19:12:06 +00:00
const devClientId = '3a723b10ac5575cc5bb9'
const devClientSecret = '22c34d87789a365981ed921352a7b9a8c3f69d54'
2017-07-13 14:29:08 +00:00
const channel = distInfo.getReleaseChannel()
2017-04-18 07:05:02 +00:00
2017-04-17 21:47:34 +00:00
const replacements = {
2017-07-13 15:15:34 +00:00
__OAUTH_CLIENT_ID__: JSON.stringify(
process.env.DESKTOP_OAUTH_CLIENT_ID || devClientId
),
__OAUTH_SECRET__: JSON.stringify(
process.env.DESKTOP_OAUTH_CLIENT_SECRET || devClientSecret
),
2017-04-17 21:47:34 +00:00
__DARWIN__: process.platform === 'darwin',
2017-04-18 07:05:02 +00:00
__WIN32__: process.platform === 'win32',
2017-06-25 08:49:38 +00:00
__LINUX__: process.platform === 'linux',
2017-07-13 14:29:08 +00:00
__DEV__: channel === 'development',
__RELEASE_CHANNEL__: JSON.stringify(channel),
__UPDATES_URL__: JSON.stringify(distInfo.getUpdatesURL()),
__SHA__: JSON.stringify(distInfo.getSHA()),
__CLI_COMMANDS__: JSON.stringify(distInfo.getCLICommands()),
2017-04-18 07:05:02 +00:00
'process.platform': JSON.stringify(process.platform),
2017-07-13 14:29:08 +00:00
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
2017-04-18 07:05:02 +00:00
'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'
const externals = ['7zip']
2017-07-20 18:47:04 +00:00
if (channel === 'development') {
externals.push('devtron')
}
2017-04-17 20:24:00 +00:00
const commonConfig = {
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$/,
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: [
{
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, {
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
],
})
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'),
})
),
],
})
highlighterConfig.module.rules = [
{
test: /\.ts$/,
include: path.resolve(__dirname, 'src/highlighter'),
use: [
{
loader: 'awesome-typescript-loader',
options: {
useBabel: true,
useCache: true,
configFileName: 'tsconfig.webworker.json',
},
},
],
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,
highlighter: highlighterConfig,
2017-04-17 21:47:34 +00:00
replacements: replacements,
externals: commonConfig.externals,
2016-05-24 19:12:06 +00:00
}