-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
97 lines (85 loc) · 2.73 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
const path = require("path"),
webpack = require('webpack'),
TerserPlugin = require('terser-webpack-plugin'),
MiniCssExtractPlugin = require('mini-css-extract-plugin'),
HtmlWebPackPlugin = require("html-webpack-plugin")
module.exports = (env, options) => {
const isDev = options.mode === 'development'
return {
devtool: isDev ? 'cheap-source-map' : false,
entry: path.resolve(__dirname, "src", "app", "index.tsx"),
output: {
path: path.resolve(__dirname, "app"),
sourceMapFilename: '[file].map',
filename: 'index.js'
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js', '.scss', '.css'],
modules: ['node_modules'],
},
devtool: isDev ? 'source-map' : false,
plugins: [
// dump css into its own files
new MiniCssExtractPlugin({
filename: 'index.min.css',
}),
// build html file
new HtmlWebPackPlugin({
template: "./src/app/index.ejs",
filename: "./index.html"
}),
],
externals: {
// jquery is loaded by Freshdesk
jquery: 'jQuery',
},
optimization: {
minimize: !isDev,
minimizer: [
// https://webpack.js.org/plugins/terser-webpack-plugin/
!isDev && new TerserPlugin({
terserOptions: {
output: {
comments: false,
},
},
extractComments: false,
}),
].filter(Boolean),
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: "ts-loader",
options: {
configFile: "tsconfig.client.json"
}
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.html$/,
use: 'html-loader',
},
{
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
esModule: true,
},
},
'css-loader',
'sass-loader',
],
}
]
},
}
}