-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
105 lines (100 loc) · 3.32 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 { endsWith, some, isNodeModuleFile, GeneratorPlugin } = require("./webpack.utils");
const webpackConfig = (env) => {
const publicPath = env && env.publicPath ? env.publicPath : "/";
const production = env && env.production ? true : false;
const buildVersion = env && env.buildVersion ? env.buildVersion : production ? "Unknown" : "DEV";
const AppConfig = {
production: production,
publicPath: publicPath,
buildVersion: buildVersion,
buildDate: new Date().toString(),
env: env
};
const config = {
mode: production ? "production" : "development",
entry: {
index: ["./src/index.tsx"]
},
output: {
filename: production ? "[name].[chunkhash].js" : "[name].js",
path: path.join(__dirname, "dist"),
publicPath: publicPath
},
module: {
rules: [
{
enforce: "pre",
test: endsWith(".ts", ".tsx", ".js"),
loader: "source-map-loader",
exclude: some(isNodeModuleFile, endsWith(".html.ts"))
},
{
test: endsWith(".ts", ".tsx"),
loader: "ts-loader",
exclude: isNodeModuleFile
},
{
test: endsWith(".woff", ".woff2", ".svg", ".ttf", ".eot"),
use: [
{ loader: "file-loader" }
]
},
{
test: endsWith(".png", ".jpg", ".gif", ".bmp"),
use: [
{ loader: "file-loader" }
]
},
{
test: endsWith(".css"),
use: [
{ loader: "style-loader" },
{ loader: "css-loader" }
]
}
]
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
modules: [
path.resolve(__dirname, "src"), "node_modules"
],
alias: {
"package.json$": path.resolve(__dirname, "package.json")
}
},
devtool: "source-map",
devServer: {
contentBase: "./dist",
historyApiFallback: {
rewrites: [
{from: /.*\.html/, to: '/index.html'}
]
},
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*"
},
port: 1717
},
plugins: [
new HtmlWebpackPlugin({
title: "React Base Application",
template: "src/index.html.ts",
AppConfig: AppConfig,
chunks: ["index"],
chunksSortMode: "none"
}),
new GeneratorPlugin({
generator: () => {
return `window.AppConfig = ${JSON.stringify(AppConfig, null, "\t")};`
},
filename: "AppConfig.js"
})
]
};
return config;
};
module.exports = webpackConfig;