-
Notifications
You must be signed in to change notification settings - Fork 52
/
renderer-webpack.config.js
82 lines (78 loc) · 2.03 KB
/
renderer-webpack.config.js
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
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const lessToJs = require('less-vars-to-js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const tsImportPluginFactory = require('ts-import-plugin');
const antdThemeOverrides = lessToJs(fs.readFileSync(path.join(__dirname, './theme.less'), 'utf8'));
console.log(antdThemeOverrides);
const NODE_ENV = process.env.NODE_ENV;
module.exports = {
mode: NODE_ENV,
devtool: 'inline-source-map',
entry: './src/renderer/index.tsx',
target: 'electron-renderer',
output: {
filename: 'renderer.js',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
loader: 'ts-loader',
options: {
transpileOnly: true,
compilerOptions: {
module: 'esnext',
},
getCustomTransformers: () => ({
before: [
tsImportPluginFactory({
libraryName: 'antd',
libraryDirectory: 'es',
style: true,
}),
],
}),
},
exclude: /node_modules/,
},
{
test: /\.less$/,
loader: [
'style-loader',
'css-loader',
{
loader: 'less-loader',
options: {
javascriptEnabled: true,
modifyVars: antdThemeOverrides,
},
},
],
},
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader',
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
watchOptions: {
poll: true,
ignored: /node_modules/,
},
plugins: [
new HtmlWebpackPlugin({
title: 'Protoman',
template: './templates/index.html',
}),
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /ja|it/),
...(NODE_ENV === 'production' ? [new BundleAnalyzerPlugin()] : []),
],
};