-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
89 lines (86 loc) · 2.86 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
import path, {resolve} from "path";
import webpack, {Configuration} from "webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import ESLintPlugin from "eslint-webpack-plugin";
import {TsconfigPathsPlugin} from "tsconfig-paths-webpack-plugin";
import dotenv from "dotenv";
const globalCSS = resolve(__dirname, "./", "src/styles/globals");
const webpackConfig = (env): Configuration => ({
entry: {
index: "./src/index.tsx"
},
...(env.production || !env.development ? {} : {devtool: "eval-source-map"}),
output: {
path: path.join(__dirname, "/dist"),
filename: "[name].bundle.js"
},
performance: {hints: false},
optimization: {
splitChunks: {
chunks: "all",
minSize: 0,
cacheGroups: {
commons: {test: /[\\/]node_modules[\\/]/, name: "common", chunks: "all"}
}
}
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".json", ".css", ".scss"],
plugins: [new TsconfigPathsPlugin()]
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
options: {
transpileOnly: true
},
exclude: /dist/
},
{
test: /\.s?(a|c)ss$/,
exclude: [globalCSS],
use: [
{loader: "style-loader"},
{loader: "css-modules-typescript-loader"},
{loader: "css-loader", options: {modules: true}},
{loader: "sass-loader", options: {sourceMap: true}}
]
},
{
test: /\.s?(a|c)ss$/,
include: [globalCSS],
use: [
"style-loader",
{loader: "css-loader", options: {import: true}},
"sass-loader"
]
},
{
test: /.js$/,
loader: "source-map-loader",
enforce: "pre"
},
{
test: /\.(woff2|woff|eot|ttf|otf)$/,
use: ["file-loader"]
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: "./public/index.html"
}),
new webpack.DefinePlugin({
"process.env.PRODUCTION": env.production || !env.development,
"process.env.NAME": JSON.stringify(require("./package.json").name),
"process.env.VERSION": JSON.stringify(require("./package.json").version),
"process.env": JSON.stringify(dotenv.config().parsed)
}),
new ForkTsCheckerWebpackPlugin(),
new ESLintPlugin({files: "./src/**/*.{ts,tsx,js,jsx}"})
]
});
export default webpackConfig;