forked from NeeEoo/Funkin-Packer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
136 lines (119 loc) · 3.03 KB
/
webpack.config.js
File metadata and controls
136 lines (119 loc) · 3.03 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import path from 'path';
import webpack from 'webpack';
import CopyPlugin from 'copy-webpack-plugin';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
let entry = [
'./src/client/index.tsx'
];
let plugins = [];
let debug = true;
let devtool = debug ? 'eval-source-map' : 'source-map';
let profiler = debug;
entry.unshift('core-js/stable');
export default (env, argv) => {
const PLATFORM = env?.platform || 'web';
const prod = argv?.mode === 'production';
const mode = prod ? 'production' : 'development';
let target = 'web';
if (PLATFORM === 'electron') target = 'electron-renderer';
plugins.push(new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(mode),
'PLATFORM': JSON.stringify(PLATFORM),
'PROFILER': JSON.stringify(profiler),
'DEBUG': JSON.stringify(!prod)
}));
let outputPath = path.resolve(__dirname, 'dist');
if (prod) {
if (PLATFORM === 'electron') {
outputPath = path.resolve(__dirname, '../electron/www');
}
else {
outputPath = path.resolve(__dirname, 'web');
}
plugins.push(new CopyPlugin({
patterns: [
{from: 'src/client/resources', to: '', globOptions: {ignore: ['**/.DS_Store']}}
],
}));
debug = false;
}
else {
entry.push('webpack-dev-server/client?http://localhost:4000');
plugins.push(new CopyPlugin({
patterns: [
{from: 'src/client/resources', to: '', globOptions: {ignore: ['**/.DS_Store']}},
],
}));
}
const config = {
entry,
output: {
path: outputPath,
filename: 'static/js/index.js'
},
devServer: {
static: './dist',
},
devtool,
target,
mode,
module: {
noParse: /.*[/\\]bin[/\\].+\.js/,
rules: [
{
test: /\.tsx$/,
use: [
{loader: 'ts-loader'},
],
exclude: /node_modules/,
},
{
test: /\.ts$/,
use: [
{loader: 'ts-loader'},
],
exclude: /node_modules/,
},
{
test: /.jsx?$/,
include: [path.resolve(__dirname, 'src')],
use: [{loader: 'babel-loader', options: {presets: ['@babel/preset-react', '@babel/preset-env']}}]
},
{
test: /\.js$/,
include: [path.resolve(__dirname, 'src')],
use: [{loader: 'babel-loader', options: {presets: ['@babel/preset-env']}}]
},
{
test: /\.(html|htm)$/,
use: [{loader: 'dom'}]
},
{
test: /\.mst$/,
use: [{loader: 'raw-loader'}]
}
]
},
optimization: {
minimize: prod,
usedExports: true,
},
plugins
};
if (target === 'electron-renderer') {
config.resolve = {
alias: {'platform': path.resolve(__dirname, './src/client/platform/electron')}
};
} else {
config.resolve = {
alias: {'platform': path.resolve(__dirname, './src/client/platform/web')}
};
}
config.resolve.alias.api = path.resolve(__dirname, './src/api');
config.resolve.alias.client = path.resolve(__dirname, './src/client');
config.resolve.alias.TypedObserver = path.resolve(__dirname, './src/client/TypedObserver');
config.resolve.extensions = ['.tsx', '.ts', '.jsx', '.js'];
return config;
};