Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
95 lines (92 loc) · 2.27 KB
/
Copy pathwebpack.config.js
File metadata and controls
95 lines (92 loc) · 2.27 KB
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
const webpack = require("webpack");
const ImageminPlugin = require("imagemin-webpack-plugin").default;
const HtmlWebpackPlugin = require("html-webpack-plugin");
const WebappWebpackPlugin = require("webapp-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const NODE_ENV = process.env.NODE_ENV || "development";
const DEV_MODE = NODE_ENV !== "production";
const PORT = process.env.PORT || 3000;
const FAVICON_DIR = "./src/assets/favicon/favicon.png";
const TITLE = "React Boilerplate";
module.exports = {
entry: ["./src/index.tsx"],
mode: DEV_MODE ? "development" : "production",
devtool: DEV_MODE ? "source-map" : "",
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
options: {
configFile: DEV_MODE ? "tsconfig.json" : "tsconfig.deploy.json"
}
}
]
},
{
test: /\.(css|sass)$/,
use: [
"style-loader",
{ loader: "css-loader", options: { importLoaders: 1 } },
"sass-loader"
]
},
{
test: /\.(png|jpe?g|gif|svg)$/,
use: [
{
loader: "file-loader",
options: {}
}
]
},
{
test: /\.(ttf|eot|woff)(\?v=[0-9].[0-9].[0-9])?$/,
use: [
{
loader: "file-loader",
options: {}
}
]
}
]
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".json"]
},
output: {
path: __dirname + "/dist",
publicPath: "/",
filename: "bundle.[hash].js"
},
devServer: {
contentBase: "./dist",
compress: true,
port: PORT,
historyApiFallback: true,
open: true
},
plugins: [
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(NODE_ENV),
"process.env.PORT": JSON.stringify(PORT)
}),
new CopyWebpackPlugin([]),
new HtmlWebpackPlugin({
template: "./src/index.html",
title: TITLE,
filename: "index.html"
}),
...(FAVICON_DIR ? [new WebappWebpackPlugin(FAVICON_DIR)] : []),
new ImageminPlugin({
disable: DEV_MODE,
pngquant: {
quality: "95-100"
},
test: /\.(jpe?g|png|gif|svg)$/i
})
]
};