Skip to content

Commit aba72de

Browse files
author
Alexey Ivanov
committed
merge two configs into single file
1 parent bef436f commit aba72de

File tree

2 files changed

+40
-79
lines changed

2 files changed

+40
-79
lines changed

webpack.dev.config.ts

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,78 @@
1-
import path from "path";
2-
import webpack from "webpack";
3-
import HtmlWebpackPlugin from "html-webpack-plugin";
4-
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
5-
import ESLintPlugin from "eslint-webpack-plugin";
1+
import * as path from 'path';
2+
import HtmlWebpackPlugin from 'html-webpack-plugin';
3+
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
4+
import ESLintPlugin from 'eslint-webpack-plugin';
5+
import { Configuration, HotModuleReplacementPlugin } from 'webpack';
66

7-
interface WebpackConfiguration extends webpack.Configuration {
8-
devServer: {
9-
contentBase: string,
10-
historyApiFallback: boolean,
11-
port: number,
12-
open: boolean,
13-
hot: boolean,
14-
}
15-
}
7+
const isProd = process.env.NODE_ENV === "production";
168

17-
const config: WebpackConfiguration = {
18-
mode: "development",
9+
const config: Configuration = {
10+
mode: isProd ? 'production' : 'development',
1911
output: {
20-
publicPath: "/",
12+
path: path.resolve(__dirname, 'build'),
13+
filename: "[name].[contenthash].js",
2114
},
22-
entry: "./src/index.tsx",
15+
entry: './src/index.tsx',
2316
module: {
2417
rules: [
2518
{
2619
test: /\.(ts|js)x?$/i,
2720
exclude: /node_modules/,
2821
use: {
29-
loader: "babel-loader",
22+
loader: 'babel-loader',
3023
options: {
3124
presets: [
32-
"@babel/preset-env",
33-
"@babel/preset-react",
34-
"@babel/preset-typescript",
25+
'@babel/preset-env',
26+
'@babel/preset-react',
27+
'@babel/preset-typescript',
3528
],
3629
},
3730
},
3831
},
32+
{
33+
test: /\.css$/i,
34+
use: ['style-loader', 'css-loader'],
35+
},
36+
{
37+
test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
38+
type: 'asset/resource',
39+
},
40+
{
41+
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
42+
type: 'asset/inline',
43+
},
3944
],
4045
},
4146
resolve: {
42-
extensions: [".tsx", ".ts", ".js"],
47+
extensions: ['.tsx', '.ts', '.js'],
4348
},
4449
plugins: [
4550
new HtmlWebpackPlugin({
46-
template: "src/index.html",
51+
template: 'src/index.html',
4752
}),
48-
new webpack.HotModuleReplacementPlugin(),
53+
new HotModuleReplacementPlugin(),
4954
new ForkTsCheckerWebpackPlugin({
5055
async: false,
5156
}),
5257
new ESLintPlugin({
53-
extensions: ["js", "jsx", "ts", "tsx"],
58+
extensions: ['js', 'jsx', 'ts', 'tsx'],
5459
}),
5560
],
56-
devtool: "inline-source-map",
61+
devtool: 'inline-source-map',
5762
devServer: {
58-
contentBase: path.join(__dirname, "build"),
63+
contentBase: path.join(__dirname, 'build'),
5964
historyApiFallback: true,
6065
port: 4000,
6166
open: true,
6267
hot: true,
68+
compress: true,
69+
watchContentBase: true,
6370
},
6471
};
6572

73+
if (isProd) {
74+
delete config.devtool;
75+
delete config.devServer;
76+
}
77+
6678
export default config;

webpack.prod.config.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)