-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
257 lines (238 loc) · 6.5 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const ReactRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ForkTsCheckerNotifierPlugin = require('fork-ts-checker-notifier-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const optimizeConstEnum = require('ts-transformer-optimize-const-enum').default;
const webpack = require('webpack');
const WebpackNotifierPlugin = require('webpack-notifier');
const { InjectManifest } = require('workbox-webpack-plugin');
const IS_PRODUCTION = process.env.NODE_ENV === 'production';
const DEV_PORT = process.env.PORT || 3000;
const PACKAGE_NAME = 'SAA1099Tracker';
const typescript = {
configFile: 'tsconfig.json',
memoryLimit: 4096,
};
const plugins = [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
}),
new ForkTsCheckerWebpackPlugin(
IS_PRODUCTION
? {
async: false,
typescript: {
...typescript,
useTypescriptIncrementalApi: true,
},
}
: { typescript }
),
// CSS extraction is only enabled in production
new MiniCssExtractPlugin({ filename: '[name].css' }),
new HtmlWebpackPlugin({
template: 'templates/index.html',
inject: true,
hash: true,
minify: {
collapseWhitespace: IS_PRODUCTION
},
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'assets/resources/png/*', to: 'assets/png/[name][ext]' },
{ from: 'assets/resources/icon.*', to: 'assets/[name][ext]' },
{ from: 'assets/data/*', to: 'assets/data/[name][ext]' },
{ from: 'assets/*', to: '[name][ext]' },
{ from: 'demosongs/*', to: '' },
{ from: 'doc/*', to: '' },
],
}),
];
if (IS_PRODUCTION) {
plugins.push(
new InjectManifest({
swSrc: path.resolve(__dirname, 'src/serviceWorker.ts'),
swDest: 'sw.js',
})
);
}
else {
plugins.push(
new ReactRefreshPlugin(),
new ForkTsCheckerNotifierPlugin({
title: `${PACKAGE_NAME}: typescript`,
excludeWarnings: false,
}),
new WebpackNotifierPlugin({ title: `${PACKAGE_NAME}: webpack` }),
);
}
// Module loaders for .scss files, used in reverse order:
// compile LESS, apply PostCSS, interpret CSS as modules.
const cssLoaders = [
// Only extract CSS to separate file in production mode.
IS_PRODUCTION
? { loader: MiniCssExtractPlugin.loader }
: require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
// necessary to minify @import-ed files using cssnano
importLoaders: 1,
},
},
{
loader: require.resolve('postcss-loader'),
options: {
postcssOptions: {
plugins: [
require('autoprefixer'),
require('cssnano')({ preset: 'default' }),
],
},
},
},
{
loader: require.resolve('less-loader'),
options: {
lessOptions: {
paths: [path.resolve(__dirname, 'node_modules/bootstrap/less')],
},
},
}
];
module.exports = {
// to automatically find tsconfig.json
context: __dirname,
devtool: IS_PRODUCTION ? false : 'inline-source-map',
entry: {
app: [
'jquery',
'bootstrap',
'bootstrap-toggle',
'./src/bootstrap.mods/touchspin/bootstrap-touchspin.js',
'./src/bootstrap.mods/confirm/bootstrap-confirm.js',
'./src/commons/timer.ts',
'./src/commons/browser.ts',
'./src/commons/dev.ts',
'./src/commons/audio.ts',
'./src/commons/number.ts',
'./src/saa/SAASound.ts',
'./src/saa/SAANoise.ts',
'./src/saa/SAAEnv.ts',
'./src/saa/SAAFreq.ts',
'./src/saa/SAAAmp.ts',
'./src/player/globals.ts',
'./src/player/Sample.ts',
'./src/player/Ornament.ts',
'./src/player/Pattern.ts',
'./src/player/Position.ts',
'./src/player/PlayerRuntime.ts',
'./src/player/Player.ts',
'./src/tracker/file.import.ts',
'./src/tracker/file.dialog.ts',
'./src/tracker/file.system.ts',
'./src/tracker/file.ts',
'./src/tracker/tracklist.ts',
'./src/tracker/smporn.ts',
'./src/tracker/manager.history.ts',
'./src/tracker/manager.ts',
'./src/tracker/settings.ts',
'./src/tracker/controls.ts',
'./src/tracker/keyboard.ts',
'./src/tracker/mouse.ts',
'./src/tracker/paint.ts',
'./src/tracker/doc.ts',
'./src/tracker/gui.ts',
'./src/compiler/optimizer.ts',
'./src/compiler/renderer.ts',
'./src/compiler/index.ts',
'./src/index.ts'
],
},
devServer: {
allowedHosts: 'all',
client: {
overlay: {
warnings: true,
errors: true,
},
progress: true,
},
devMiddleware: {
index: path.resolve(__dirname, 'templates/index.html'),
stats: 'errors-only',
},
historyApiFallback: true,
https: false,
host: '0.0.0.0',
hot: true,
open: false,
port: DEV_PORT,
static: path.resolve(__dirname),
},
output: {
filename: '[name].js',
publicPath: '/',
path: path.resolve(__dirname, 'build'),
},
mode: IS_PRODUCTION ? 'production' : 'development',
module: {
rules: [
{
test: /\.js$/,
use: require.resolve('source-map-loader'),
},
{
test: /\.tsx?$/,
loader: require.resolve('ts-loader'),
options: {
configFile: 'tsconfig.json',
transpileOnly: true,
getCustomTransformers: (program) => ({
before: [optimizeConstEnum(program)],
afterDeclarations: [optimizeConstEnum(program)],
}),
},
},
{
test: /\.less$/,
use: cssLoaders,
},
{
test: /\.html$/,
loader: require.resolve('underscore-template-loader'),
include: path.resolve(__dirname, 'templates'),
},
{
test: /\.(eot|ttf|woff|woff2|svg)$/,
type: 'asset/resource',
generator: {
filename: 'assets/[name][ext]?[contenthash]',
},
},
{
test: /\.(ico|png)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [
{
loader: 'file-loader',
options: {
esModule: false,
name: 'assets/[name].[ext]?[contenthash]',
},
},
],
}
],
},
plugins,
resolve: {
extensions: ['.js', '.ts', '.less'],
},
target: 'browserslist',
};