-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
111 lines (110 loc) · 3.19 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
const path = require('path')
const fs = require('fs')
const CopyPlugin = require('copy-webpack-plugin')
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
const CircularDependencyPlugin = require('circular-dependency-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
const CssClassnameGenerator = require('./webpack/CssClassnameGenerator')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
module.exports = function (env, argv) {
const tsConfig = JSON.parse(fs.readFileSync(path.join(__dirname, 'tsconfig.json')))
const isProduction = argv.mode === 'production'
return {
entry: './src/index.tsx',
target: 'web',
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'bin')
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /(\.css|\.less)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false,
modules: {
getLocalIdent: CssClassnameGenerator({ isProduction })
}
}
},
'less-loader'
]
},
{
test: /\.(txt|md)$/,
use: 'raw-loader'
}
]
},
resolve: {
extensions: ['*', '.ts', '.tsx', '.js', '.jsx', '.css', '.less', '.txt', '.md'],
alias: Object.entries(tsConfig.compilerOptions.paths).reduce((acc, [name, loc]) => {
const key = name.endsWith('/*') ? name.slice(0, -2) : name
const value = path.join(
__dirname,
tsConfig.compilerOptions.baseUrl,
loc[0].endsWith('/*') ? loc[0].slice(0, -2) : loc[0]
)
acc[key] = value
return acc
}, {})
},
plugins: [
new CleanWebpackPlugin(),
new webpack.ProvidePlugin({
classes: ['£classes']
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html',
inject: 'body',
scriptLoading: 'blocking',
hash: true,
cache: false,
publicPath: '/'
}),
new CopyPlugin({
patterns: [
{ from: './assets', to: 'assets' }
]
}),
new CaseSensitivePathsPlugin(),
new CircularDependencyPlugin({
exclude: /node_modules/,
failOnError: true,
allowAsyncCycles: false
}),
new MiniCssExtractPlugin({ filename: 'index.css' })
],
optimization: {
minimize: isProduction,
...(isProduction
? {
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
output: { comments: false },
compress: { }
}
}),
new CssMinimizerPlugin()
]
}
: undefined)
}
}
}