next-ucap-messenger/config/main.webpack.config.ts

134 lines
3.5 KiB
TypeScript
Raw Normal View History

2019-09-18 06:02:21 +00:00
import * as path from 'path';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
2019-10-21 09:26:17 +00:00
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
2019-09-18 06:02:21 +00:00
import * as webpack from 'webpack';
import * as nodeExternals from 'webpack-node-externals';
import { getEnviroments } from './enviroment';
const enviroments = getEnviroments();
export const externals = [nodeExternals()];
// if (enviroments.__DEV__) {
// externals.push('devtron');
// }
2019-11-11 06:53:39 +00:00
const outputDir = 'dist/ucap-webmessenger-electron';
2019-09-18 06:02:21 +00:00
const mainConfig: webpack.Configuration = {
2019-11-11 06:53:39 +00:00
entry: {
main: path.resolve(
__dirname,
'..',
'electron-projects/ucap-webmessenger-electron/src/index'
2019-11-12 09:54:21 +00:00
),
2019-11-11 06:53:39 +00:00
},
2019-09-18 06:02:21 +00:00
target: 'electron-main',
mode: enviroments.__DEV__ ? 'development' : 'production',
devtool: 'source-map',
optimization: {
2019-11-12 09:54:21 +00:00
noEmitOnErrors: true,
2019-09-18 06:02:21 +00:00
},
externals,
output: {
filename: '[name].js',
2019-11-12 09:54:21 +00:00
path: path.resolve(__dirname, '..', outputDir),
2019-09-18 06:02:21 +00:00
},
module: {
rules: [
{
test: /\.tsx?$/,
include: [
2019-11-11 06:53:39 +00:00
path.resolve(
__dirname,
'..',
'electron-projects/ucap-webmessenger-electron/src'
),
path.resolve(__dirname, '..', 'electron-projects'),
2019-11-12 09:54:21 +00:00
path.resolve(__dirname, '..', 'projects'),
2019-09-18 06:02:21 +00:00
],
use: [
{
loader: 'awesome-typescript-loader',
options: {
useCache: true,
configFileName: path.resolve(
__dirname,
'..',
2019-11-11 06:53:39 +00:00
'electron-projects/ucap-webmessenger-electron/tsconfig.electron.json'
2019-11-12 09:54:21 +00:00
),
},
},
2019-09-18 06:02:21 +00:00
],
2019-11-12 09:54:21 +00:00
exclude: /node_modules/,
2019-09-18 06:02:21 +00:00
},
{
test: /\.node$/,
loader: 'awesome-node-loader',
options: {
2019-11-12 09:54:21 +00:00
name: '[name].[ext]',
},
},
],
2019-09-18 06:02:21 +00:00
},
plugins: [
new CleanWebpackPlugin({ verbose: false }),
// This saves us a bunch of bytes by pruning locales (which we don't use)
// from moment.
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.DefinePlugin(
Object.assign({}, enviroments, {
2019-11-12 09:54:21 +00:00
__PROCESS_KIND__: JSON.stringify('main'),
2019-09-18 06:02:21 +00:00
})
2019-10-21 09:26:17 +00:00
),
new CopyWebpackPlugin([
{
2019-11-11 06:53:39 +00:00
from: 'ucap-webmessenger-electron/resources/**/*',
to: path.resolve(__dirname, '..', 'dist'),
2019-11-12 09:54:21 +00:00
context: 'electron-projects',
},
]),
2019-09-18 06:02:21 +00:00
],
resolve: {
extensions: ['.js', '.ts'],
alias: {
2019-11-09 08:29:02 +00:00
'@ucap-webmessenger/electron-core': path.resolve(
__dirname,
'..',
2019-11-11 06:53:39 +00:00
'electron-projects/ucap-webmessenger-electron-core/src/public-api'
2019-11-09 08:29:02 +00:00
),
'@ucap-webmessenger/electron-notification': path.resolve(
__dirname,
'..',
2019-11-11 06:53:39 +00:00
'electron-projects/ucap-webmessenger-electron-notification/src/public-api'
2019-11-09 08:29:02 +00:00
),
2019-11-12 09:54:21 +00:00
'@ucap-webmessenger/core': path.resolve(
__dirname,
'..',
'projects/ucap-webmessenger-core/src/public-api'
),
2019-09-18 06:02:21 +00:00
'@ucap-webmessenger/native': path.resolve(
__dirname,
'..',
'projects/ucap-webmessenger-native/src/public-api'
),
'@ucap-webmessenger/native-electron': path.resolve(
__dirname,
'..',
'projects/ucap-webmessenger-native-electron/src/public-api'
2019-11-11 06:53:39 +00:00
),
'@ucap-webmessenger/electron': path.resolve(
__dirname,
'..',
'electron-projects/ucap-webmessenger-electron/src/public-api'
2019-11-12 09:54:21 +00:00
),
2019-09-18 06:02:21 +00:00
},
2019-11-12 09:54:21 +00:00
modules: [path.resolve(__dirname, '..', 'node_modules/')],
2019-09-18 06:02:21 +00:00
},
node: {
__dirname: false,
2019-11-12 09:54:21 +00:00
__filename: false,
},
2019-09-18 06:02:21 +00:00
};
export default [mainConfig];