This repository was archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.ts
128 lines (114 loc) · 3.06 KB
/
webpack.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import path from 'path';
import merge from 'webpack-merge';
import NodeExternals from 'webpack-node-externals';
// import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import ExtractCssChunksPlugin from 'extract-css-chunks-webpack-plugin';
import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import NullPlugin from 'webpack-null-plugin';
import { Configuration } from 'webpack';
const devMode = process.env.NODE_ENV === 'development';
const baseConfig: Configuration = {
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js',
publicPath: 'build/',
},
node: {
__dirname: false,
__filename: false,
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js', '.json'],
},
devtool: 'source-map',
watchOptions: {
ignored: /node_modules/,
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
},
{
test: /\.(sa|sc|c)ss$/,
use: [ExtractCssChunksPlugin.loader, 'css-loader', 'sass-loader'],
},
{
test: /\.pug$/,
loader: 'file-loader',
options: {
name: 'views/[name].[ext]',
},
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: 'images/[name].[ext]',
publicPath: '../',
},
},
{
test: /\.(ttf|eot|woff|woff2)$/,
use: {
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
},
},
},
],
},
externals: [NodeExternals()],
};
const developmentConfig: Configuration = {
optimization: {
splitChunks: false,
removeEmptyChunks: false,
},
};
const productionConfig: Configuration = {
optimization: {
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: false,
}),
new OptimizeCSSAssetsPlugin({}),
],
},
};
const mainConfig = merge.smart(baseConfig, {
target: 'electron-main',
entry: {
main: './src/main/index.ts',
},
plugins: [
devMode ? new NullPlugin() : new ForkTsCheckerWebpackPlugin({ tslint: true }), // tslint
new ExtractCssChunksPlugin(),
],
});
const mainDevConfig = merge.smart(mainConfig, developmentConfig);
const mainProdConfig = merge.smart(mainConfig, productionConfig);
const rendererConfig = merge.smart(baseConfig, {
target: 'electron-renderer',
entry: {
splash: './src/renderer/splash.tsx',
app: './src/renderer/app.tsx',
},
plugins: [new ExtractCssChunksPlugin()],
});
const rendererDevConfig = merge.smart(rendererConfig, developmentConfig);
const rendererProdConfig = merge.smart(rendererConfig, productionConfig);
export default (devMode
? [mainDevConfig, rendererDevConfig] // dev
: [mainProdConfig, rendererProdConfig]); // production