-
Notifications
You must be signed in to change notification settings - Fork 48
/
webpack.config.js
100 lines (95 loc) · 2.48 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
var webpack = require("webpack");
var production = process.argv.find((x) => x === "-p");
var fs = require("fs");
var StringReplacePlugin = require("string-replace-webpack-plugin");
var appVersion = require("./package.json").version;
var nonJSAssets = [
"style.css",
"apple-touch-icon.png",
"fonts/fabric-icons-72e4a0ad.woff",
"fonts/fabric-icons-8d8d4ac2.woff",
"fonts/segoeui-westeuropean/segoeui-light.woff",
"fonts/segoeui-westeuropean/segoeui-light.woff2",
"fonts/segoeui-westeuropean/segoeui-regular.woff",
"fonts/segoeui-westeuropean/segoeui-regular.woff2",
"fonts/segoeui-westeuropean/segoeui-semibold.woff",
"fonts/segoeui-westeuropean/segoeui-semibold.woff2",
"fonts/segoeui-westeuropean/segoeui-semilight.woff",
"fonts/segoeui-westeuropean/segoeui-semilight.woff2",
];
var processHTML = {
apply: (compiler) => {
compiler.hooks.afterEmit.tap("AfterEmitPlugin", (compilation) => {
const assets = JSON.stringify(
Object.keys(compilation.assets).concat(nonJSAssets)
).replace(/\[|\]/g, "");
const HTMLFile = fs.readFileSync("./src/index.html", {
encoding: "utf8",
});
fs.writeFileSync(
"./dist/application/index.html",
HTMLFile.replace("/*ASSETS_PLACEHOLDER*/", assets)
);
});
},
};
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
module.exports = {
entry: "./src/app.tsx",
output: {
filename: "app.js",
path: __dirname + "/dist/application",
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".json", ".css", ".scss"],
plugins: [new TsconfigPathsPlugin({})],
},
externals: {
moment: "moment",
fs: "fs",
path: "path",
crypto: "crypto",
},
mode: production ? "production" : "development",
module: {
rules: [
{
test: /\.tsx?$/,
loader: [
"ts-loader",
StringReplacePlugin.replace({
replacements: [
{
pattern: /--VERSION--/g,
replacement: () => appVersion,
},
],
}),
],
},
{
enforce: "pre",
test: /\.js$/,
loader: "source-map-loader",
},
],
},
plugins: production
? [
processHTML,
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production"),
}),
new StringReplacePlugin(),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 5,
}),
]
: [
processHTML,
new StringReplacePlugin(),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 5,
}),
],
};