-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
168 lines (151 loc) · 5.22 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import * as webpack from "webpack";
import * as path from "path";
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const autoprefixer = require("autoprefixer");
const tsImportPluginFactory = require("ts-import-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
function env(global_env: any): "development" | "production" {
return global_env ? global_env : "development";
}
function isArr(x: any): x is any[] {
return typeof x !== "undefined";
}
const css = new ExtractTextPlugin({
// allChunks: true,
filename: "[id].[name].[contenthash].css",
disable: process.env.NODE_ENV === "development",
});
const stylus = new ExtractTextPlugin({
// allChunks: true,
filename: "[id].[name].[contenthash].css",
disable: process.env.NODE_ENV === "development",
});
const webpackConfig: webpack.Configuration = {
entry: process.env.NODE_ENV === "production" ? "./src/main.tsx" : [
"webpack-hot-middleware/client?path=/__webpack_hmr&timeout=2000&reload=true",
"./src/main.tsx",
],
target: "electron-renderer",
mode: env(process.env.NODE_ENV),
devServer: {
contentBase: path.join(__dirname, "dist"),
historyApiFallback: true,
compress: true,
noInfo: false,
hot: true, // hot module replacement. Depends on HotModuleReplacementPlugin
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
enforce: "pre",
loader: "tslint-loader",
},
{
test: /\.tsx?$/,
use: [
{ loader: "babel-loader" },
{
loader: "ts-loader",
options: {
transpileOnly: true,
getCustomTransformers: () => ({
before: [tsImportPluginFactory({
libraryName: "antd",
libraryDirectory: "lib",
style: "css",
})],
}),
compilerOptions: {
module: "es2015",
},
},
},
],
exclude: /node_modules/,
},
{
test: /\.css$/,
loader: css.extract({
fallback: "style-loader",
use: [
{
loader: "css-loader",
options: {
minimize: true,
sourceMap: true,
},
},
],
}),
},
{
test: /\.styl$/,
loader: stylus.extract({
fallback: "style-loader",
use: [
{
loader: "css-loader",
options: {
minimize: true,
sourceMap: true,
},
},
{
loader: "postcss-loader",
options: {
sourceMap: true,
plugins: () => [autoprefixer],
},
},
{
loader: "stylus-loader",
options: {
sourceMap: true,
paths: "src/resources/styles",
},
},
],
}),
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
alias: {
"@route": path.join(__dirname, "/src/route/"),
"@views": path.join(__dirname, "/src/views/"),
"@store": path.join(__dirname, "/src/store/"),
"@components": path.join(__dirname, "/src/components"),
"@utils": path.join(__dirname, "/src/utils"),
"@main": path.join(__dirname, "/src/main_process"),
},
},
output: {
filename: "[name].[hash].js",
path: path.join(__dirname, "dist"),
// publicPath: "/",
},
devtool: "source-map",
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, "/config/template.html"),
title: "Corky Cherry",
}),
css,
stylus,
],
};
if (isArr(webpackConfig.plugins) && process.env.NODE_ENV === "production") {
webpackConfig.plugins.push(
new CopyWebpackPlugin([
{ from: "config/package.json", to: "package.json" },
{ from: "config/note.readme.md", to: "note.readme.md" },
]),
);
}
export default webpackConfig;