-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
107 lines (106 loc) · 2.7 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
const path = require('path');
const {DefinePlugin} = require('webpack');
const ESLintPlugin = require('eslint-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = function (env, { mode }) {
return {
mode: mode || 'development',
devtool: 'source-map',
entry: './src/index.tsx',
devServer: {
port: 8080,
historyApiFallback: true,
client: {
overlay: false,
},
},
output: {
publicPath: mode === 'production' ? '/faraway-test-task/' : "/",
filename: `js/bundle${mode === "production" ? ".[fullhash]" : ""}.js`,
chunkFilename: 'js/chunks/[name].[contenthash].js',
},
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
extensions: ['.ts', '.tsx', '.js', '.jsx', '.less'],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: ['@babel/preset-react', '@babel/preset-typescript'],
},
},
{
test: /\.less$/i,
use: [
{
loader: mode !== "production" ? "style-loader" : MiniCssExtractPlugin.loader,
},
'css-loader',
{
loader: "less-loader",
options: {
lessOptions: {
javascriptEnabled: true,
modifyVars: {
'primary-color': '#3772FF',
'link-color': '#3772FF',
},
},
}
}
],
},
{
test: /\.css$/,
use: [
{
loader: mode !== "production" ? "style-loader" : MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
sourceMap: true,
modules: {
localIdentName: mode === "production" ? "[local]-[hash:base64:5]" : "[path]__[local]--[hash:base64:5]",
},
},
},
],
},
],
},
plugins: [
new ESLintPlugin(),
new HtmlWebpackPlugin({
template: './public/index.html',
favicon: './public/favicon.ico',
publicPath: mode === 'production' ? '/faraway-test-task' : "/",
minify: mode === 'production' && {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
new DefinePlugin({
'process.env.PUBLIC_URL': JSON.stringify(process.env.PUBLIC_URL),
}),
].concat(mode !== 'production' ? [] : [
new MiniCssExtractPlugin({
filename: `css/bundle${mode === "production" ? ".[fullhash]" : ""}.css`,
chunkFilename: "css/chunks/[name].[contenthash].css",
}),
]),
};
};