-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathwebpack.app.config.js
83 lines (79 loc) · 2.13 KB
/
webpack.app.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
const process = require("global/process");
const path = require("path");
const merge = require("webpack-merge");
const nodeExternals = require("webpack-node-externals");
const FriendlyErrorsWebpackPlugin = require("friendly-errors-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");
const { join } = require("path");
const { rootPath } = require("electron-root-path");
const pkg = require(join(rootPath, "package.json"));
const translateEnvToMode = env => {
if (env === "production") {
return "production";
}
return "development";
};
const globalState = require("./global-state");
const base = env => {
env = env || process.env.NODE_ENV || "production";
return {
target: "electron-renderer",
mode: translateEnvToMode(env),
node: {
__dirname: false,
__filename: false
},
externals: [nodeExternals()],
resolve: {
alias: {
env: path.resolve(__dirname, `../config/env_${env}.json`)
}
},
devtool: "source-map",
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ["babel-loader"]
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
GLOBAL_STATE: JSON.stringify(globalState),
NODE_ENV: JSON.stringify(env),
version: JSON.stringify(pkg.version),
author: JSON.stringify(pkg.author)
}
}),
new FriendlyErrorsWebpackPlugin({ clearConsole: env === "development" }),
new CopyPlugin([
{ from: "./src/index.html" },
{ from: "./src/about.html" },
{ from: "./src/about.js" },
{ from: "./src/icon.png" },
{ from: "../../dist/stylesheets/main.css" },
{ from: "../../dist/antd.css" }
])
]
};
};
module.exports = env => {
return merge(base(env), {
entry: {
main: "./src/main.js",
renderer: "./src/renderer.js"
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "./dist/app")
}
});
};