-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
105 lines (103 loc) · 3.02 KB
/
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const isWebpackDevServer = process.argv[1].indexOf('webpack-dev-server') !== -1
const webpack = require('webpack')
const port = process.env.PORT || 8081
const { version } = require('./package.json')
const mode = isWebpackDevServer ? "development" : "production"
const src = path.join(__dirname, 'src', 'renderer')
module.exports = {
mode,
target: 'electron-renderer',
devServer: {
historyApiFallback: true,
contentBase: "./",
hot: true,
host: "0.0.0.0",
headers: {
'Access-Control-Allow-Origin': "*"
},
clientLogLevel: "error",
stats: "minimal",
port
},
optimization: {
// We no not want to minimize our code.
minimize: false
},
entry: {
app: [
isWebpackDevServer ? `webpack-dev-server/client?http://localhost:${port}` : null,
path.join(__dirname, "./src/renderer/index.tsx")
].filter(e => !!e)
},
output: {
path: path.join(__dirname, "./dist"),
filename: "[name].js",
publicPath: isWebpackDevServer ? '/' : '../dist'
},
devtool: "sourcemap",
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src', 'renderer', 'index.html'),
// Appends unique hash to each resource, helps with cache busting in production
hash: !isWebpackDevServer
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env.VERSION': JSON.stringify(version),
'process.env.PLATFORM': JSON.stringify(process.env.PLATFORM)
}),
new MiniCssExtractPlugin({
filename: 'styles.css',
})
],
module: {
rules: [
{
test: /\.(ts|js)x?$/,
use: [
{
loader: 'babel-loader'
},
{
loader: 'linaria/loader',
options: {
sourceMap: process.env.NODE_ENV !== 'production',
},
}
],
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: process.env.NODE_ENV !== 'production',
},
},
{
loader: 'css-loader',
options: {
sourceMap: process.env.NODE_ENV !== 'production',
},
},
],
},
]
},
resolve: {
extensions: [
".ts",
".tsx",
".js",
".jsx"
],
modules: [
"node_modules"
],
symlinks: false
}
}