github-desktop/app/webpack.common.js

131 lines
2.9 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')
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-17 20:24:00 +00:00
const commonConfig = {
externals: [
'electron',
'net',
'remote',
'shell',
'app',
'ipc',
'keytar',
'7zip',
'dugite',
],
2016-05-24 19:12:06 +00:00
output: {
2016-06-24 13:52:24 +00:00
filename: '[name].js',
2017-04-17 20:24:00 +00:00
path: path.resolve(__dirname, '..', 'out'),
2016-05-24 19:12:06 +00:00
libraryTarget: 'commonjs2'
},
2017-04-17 20:24:00 +00:00
plugins: [
new webpack.NoEmitOnErrorsPlugin()
],
resolve: {
extensions: [ '.js', '.ts', '.tsx' ],
modules: [ path.resolve(__dirname, 'node_modules/') ],
mainFields: ['webpack', 'browser', 'web', 'browserify', ['jam', 'main'], 'main']
},
node: {
__dirname: false,
__filename: false
},
}
const mainConfig = merge({}, commonConfig, {
entry: { main: path.resolve(__dirname, 'src/main-process/main') },
target: 'electron-main',
module: {
rules: [
{
test: /\.ts$/,
include: path.resolve(__dirname, 'src'),
use: 'ts-loader',
exclude: /node_modules/,
}
]
},
})
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: [
2016-05-24 19:12:06 +00:00
{
test: /\.tsx?$/,
2017-04-17 20:24:00 +00:00
include: path.resolve(__dirname, 'src'),
use: 'ts-loader',
exclude: /node_modules/,
},
{
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-04-17 20:24:00 +00:00
],
})
const sharedConfig = merge({}, commonConfig, {
entry: { shared: path.resolve(__dirname, 'src/shared-process/index') },
target: 'electron-renderer',
module: {
rules: [
{
test: /\.ts$/,
include: path.resolve(__dirname, 'src'),
use: 'ts-loader',
exclude: /node_modules/,
}
]
},
plugins: [
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
}),
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',
module: {
rules: [
{
test: /\.ts$/,
include: path.resolve(__dirname, 'src'),
use: 'ts-loader',
exclude: /node_modules/,
}
]
},
2017-04-17 20:24:00 +00:00
})
module.exports = {
main: mainConfig,
shared: sharedConfig,
renderer: rendererConfig,
askPass: askPassConfig,
replacements: {
2017-04-13 14:09:57 +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),
__DARWIN__: process.platform === 'darwin',
__WIN32__: process.platform === 'win32'
2016-05-24 19:12:06 +00:00
}
}