Repository navigation
Expand file tree
/
Copy pathwebpack.config.mjs
More file actions
78 lines (77 loc) · 2.7 KB
/
Copy pathwebpack.config.mjs
File metadata and controls
78 lines (77 loc) · 2.7 KB
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
import { resolve as resolvePath } from "node:path";
import webpack from "webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import autoprefixer from "autoprefixer"
export default function(env, argv) {
return {
entry: [resolvePath('.', 'src', 'main', 'ts', 'index.ts'), resolvePath('.', 'src', 'main', 'scss', 'index.scss')],
mode: env.production ? 'production' : 'development',
devtool: env.production ? 'source-map' : 'eval-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
options: { configFile: resolvePath('.', 'config', env.production ? 'tsconfig.dist.json' : 'tsconfig.dev.json') }
}
],
exclude: /node_modules/,
},
{
test: /\.s[ac]ss$/,
use: [
env.production ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
autoprefixer
]
}
}
},
'sass-loader'
]
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource'
}
],
},
devServer: {
static: {
directory: resolvePath('.', 'build')
},
client: {
overlay: false
},
open: true,
compress: true,
port: 9908,
hot: true
},
resolve: { extensions: ['.tsx', '.ts', '.js'], },
output: {
filename: env.production ? 'index.bundle.min.mjs' : 'index.bundle.mjs',
path: resolvePath('.', 'build'),
clean: true
},
plugins: [
new MiniCssExtractPlugin({ filename: "index.min.css" }),
new HtmlWebpackPlugin({
template: resolvePath('.', 'src', 'main', 'html', 'index.html'),
scriptLoading: 'module'
})
]
}
};