-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
119 lines (111 loc) · 2.71 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const WarningsToErrorsPlugin = require('warnings-to-errors-webpack-plugin');
const deps = require("./package.json").dependencies;
const path = require("path");
const isProduction = process.env.NODE_ENV === "production";
const lintConfigProduction = {
context: './src',
extensions: ['ts', 'tsx'],
emitWarning: true,
emitError: true
};
const lintConfigDevelopment = {
context: './src',
extensions: ['ts', 'tsx'],
exclude: ['public', 'node_modules', 'base/extends'],
failOnError: false,
failOnWarning: false,
emitWarning: true
};
let plugins = [
new ESLintPlugin(isProduction ? lintConfigProduction : lintConfigDevelopment),
new CopyWebpackPlugin({
patterns: [
{ from: './src/public/assets', to: 'assets' },
{ from: './src/public/config', to: 'config' }
]
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "src/public", "index.ejs")
}),
new ForkTsCheckerWebpackPlugin()
];
if (isProduction) {
plugins = plugins.concat([
new WarningsToErrorsPlugin()
]);
}
module.exports = {
mode: process.env.NODE_ENV === "production" ? "production" : "development",
entry: { index: path.resolve(__dirname, "src", "index.tsx") },
devtool: isProduction ? undefined : "cheap-module-source-map",
output: {
publicPath: process.env.NODE_ENV === "production" ? "/" : "http://localhost:8082/",
},
module: {
rules: [
{
test: /\.(tsx|ts)?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
transpileOnly: true
}
},
{
test: /\.(js|jsx)?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.(s[ac]|c)ss$/i,
use: ["style-loader", "css-loader?url=false", "postcss-loader", "sass-loader"]
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
type: "asset"
}
]
},
resolve: {
extensions: ['.ts', '.js', '.tsx', '.jsx', '.json'],
plugins: [
new TsconfigPathsPlugin({})
],
},
plugins,
optimization: isProduction ? {
splitChunks: {
minSize: 700000,
maxSize: 1000000
}
} : undefined,
performance: {
hints: 'error',
maxAssetSize: isProduction ? 1001000 : Infinity,
maxEntrypointSize: isProduction ? 1001000 : Infinity
},
devServer: {
port: 8082,
historyApiFallback: true,
hot: true,
stats: {
colors: true,
hash: false,
version: false,
assets: false,
chunks: false,
modules: false,
reasons: false,
children: false,
source: false,
publicPath: false
}
},
};