This repository has been archived by the owner on Jul 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.common.js
109 lines (105 loc) · 2.43 KB
/
webpack.common.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
106
107
108
109
const path = require("path")
const webpack = require("webpack")
const CopyWebpackPlugin = require("copy-webpack-plugin")
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin")
const HappyPack = require("happypack")
const packageJson = require("./package.json")
const outDirName = "out"
const outPath = path.resolve(__dirname, outDirName)
const srcDirName = "src"
const srcPath = path.resolve(__dirname, srcDirName)
const staticResPath = "./src/res/static"
const browserIconPath = "./build/icons/128x128.png"
const browserIconOutFilename = "icon.png"
const htmlTemplatePath = path.join(srcDirName, "index.html")
const rendererEntry = "./src/renderer.tsx"
const dllConfig = {
dllRelativePath: "./dll",
vendorBundleFilename: "vendor.bundle.js",
vendorManifestFilename: "vendor-manifest.json"
}
const mainConfig = {
target: "electron-main",
entry: { main: "./src/main.ts" },
output: {
filename: "main.bundle.js",
path: outPath
},
module: {
rules: [
{
test: /.ts$/,
use: ["cache-loader", "babel-loader", "ts-loader"],
include: srcPath
}
]
},
resolve: {
extensions: [".js", ".ts", ".json"],
alias: {
"~": path.resolve("./src")
},
symlinks: false
},
plugins: [
new CopyWebpackPlugin([
{ from: staticResPath },
{ from: browserIconPath, to: browserIconOutFilename }
])
]
}
const rendererConfig = {
context: __dirname,
target: "electron-renderer",
output: {
filename: "renderer.bundle.js",
path: outPath
},
module: {
rules: [
{
test: /tsx?$/,
loader: "happypack/loader?id=ts"
},
{
test: /(png|jpg|gif|woff2)$/,
loader: "url-loader?limit=100000"
}
]
},
resolve: {
extensions: [".js", ".ts", ".tsx"],
alias: {
"~": path.resolve("./src")
},
symlinks: false
},
plugins: [
new webpack.DefinePlugin({
VERSION: JSON.stringify(packageJson.version)
}),
new HappyPack({
id: "ts",
threads: 2,
loaders: [
"cache-loader",
"babel-loader",
{
path: "ts-loader",
query: { happyPackMode: true }
}
]
}),
new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true, watch: ["./src"] }),
new webpack.NoEmitOnErrorsPlugin()
]
}
module.exports = {
mainConfig,
rendererConfig,
outDirName,
srcPath,
htmlTemplatePath,
rendererEntry,
dllConfig
}