-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.config.ts
76 lines (72 loc) · 2.23 KB
/
webpack.prod.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
import path from "path";
import { Configuration } from "webpack";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import ESLintPlugin from "eslint-webpack-plugin";
import CopyWebpackPlugin from 'copy-webpack-plugin'
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import webpack from "webpack";
const getEnvKeys = () => {
const envKeys = {
'process.env.API_HOST': JSON.stringify(process.env.API_HOST),
'process.env.API_PORT': JSON.stringify(process.env.API_PORT)
}
return envKeys
}
const config: Configuration = {
mode: "production",
entry: "./src/index.tsx",
output: {
path: path.resolve(__dirname, "build"),
filename: "[name].[contenthash].js",
publicPath: "",
},
module: {
rules: [
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader"]
},
{
test: /\.(ts|js)x?$/i,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript",
],
},
},
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
plugins: [
new HtmlWebpackPlugin({
template: "src/index.html",
favicon: path.resolve(__dirname, "src", "assets", "favicon.ico")
}),
new ForkTsCheckerWebpackPlugin({ async: false }),
new ESLintPlugin({ extensions: ["js", "jsx", "ts", "tsx"] }),
new CleanWebpackPlugin(),
new webpack.DefinePlugin(getEnvKeys()),
new CopyWebpackPlugin({
patterns: [
{ from: 'src/assets', to: 'assets' },
{ from: 'pwa.json', to: 'pwa.json' },
{ from: 'sw.js', to: 'sw.js' }
]
}),
],
optimization: {
splitChunks: {
chunks: 'all'
}
}
};
export default config;