forked from StrandedKitty/streets-gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
107 lines (105 loc) · 2.59 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 CopyPlugin = require('copy-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const {EsbuildPlugin} = require('esbuild-loader');
const childProcess = require('child_process');
const {DefinePlugin} = require("webpack");
const COMMIT_SHA = childProcess.execSync('git rev-parse HEAD').toString().trim();
const COMMIT_BRANCH = childProcess.execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
const VERSION = require('./package.json').version;
module.exports = (env, argv) => ([{
entry: './src/app/App.ts',
output: {
filename: './js/index.js',
path: path.resolve(__dirname, 'build')
},
performance: {
maxEntrypointSize: 8000000,
maxAssetSize: 8000000
},
optimization: {
minimizer: [
new EsbuildPlugin({
target: 'es2020'
})
]
},
devServer: {
hot: true
},
devtool: argv.mode === 'production' ? undefined : 'inline-source-map',
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html',
minify: argv.mode === 'production'
}),
new MiniCssExtractPlugin(),
new CopyPlugin({
patterns: [
{from: './src/resources/textures', to: path.resolve(__dirname, 'build/textures')},
{from: './src/resources/models', to: path.resolve(__dirname, 'build/models')},
{from: './src/resources/images', to: path.resolve(__dirname, 'build/images')}
]
}),
new ESLintPlugin({
context: './src',
extensions: ['ts', 'tsx']
}),
new DefinePlugin({
COMMIT_SHA: JSON.stringify(COMMIT_SHA),
COMMIT_BRANCH: JSON.stringify(COMMIT_BRANCH),
VERSION: JSON.stringify(VERSION)
})
],
module: {
rules: [
{
test: /\.vert|.frag|.glsl$/i,
use: [
{
loader: 'raw-loader',
options: {
esModule: false,
},
},
]
}, {
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader']
}, {
test: /\.s[ac]ss$/i,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: true,
url: false
},
},
'sass-loader'
],
sideEffects: true
}, {
test: /\.[jt]sx?$/,
loader: 'esbuild-loader',
options: {
target: 'es2020',
tsconfig: argv.mode === 'production' ? 'tsconfig.prod.json' : 'tsconfig.json'
}
},
]
},
resolve: {
extensions: ['.ts', '.js', '.tsx'],
alias: {
'~': path.resolve(__dirname, 'src')
}
}
}]);