@logue/reverb 0.4.4 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -10
- package/dist/reverb.es.js +188 -0
- package/dist/reverb.umd.js +10 -0
- package/package.json +59 -44
- package/types/Meta.d.ts +4 -0
- package/types/Meta.d.ts.map +1 -0
- package/types/NoiseType.d.ts +14 -0
- package/types/NoiseType.d.ts.map +1 -0
- package/types/Reverb.d.ts +118 -0
- package/types/Reverb.d.ts.map +1 -0
- package/{src/interfaces/MetaInterface.ts → types/interfaces/MetaInterface.d.ts} +2 -3
- package/{dist → types}/interfaces/MetaInterface.d.ts.map +1 -1
- package/{src/interfaces/OptionInterface.ts → types/interfaces/OptionInterface.d.ts} +5 -5
- package/types/interfaces/OptionInterface.d.ts.map +1 -0
- package/.eslintignore +0 -4
- package/.eslintrc.js +0 -21
- package/.gitattributes +0 -1
- package/.prettierrc.js +0 -3
- package/bin/reverb.js +0 -432
- package/bin/reverb.js.map +0 -1
- package/bin/reverb.min.js +0 -2
- package/bin/reverb.min.js.LICENSE.txt +0 -11
- package/dist/Meta.d.ts +0 -4
- package/dist/Meta.d.ts.map +0 -1
- package/dist/Meta.js +0 -9
- package/dist/Meta.js.map +0 -1
- package/dist/NoiseType.d.ts +0 -7
- package/dist/NoiseType.d.ts.map +0 -1
- package/dist/NoiseType.js +0 -12
- package/dist/NoiseType.js.map +0 -1
- package/dist/Reverb.d.ts +0 -114
- package/dist/Reverb.d.ts.map +0 -1
- package/dist/Reverb.js +0 -331
- package/dist/Reverb.js.map +0 -1
- package/dist/interfaces/MetaInterface.d.ts +0 -10
- package/dist/interfaces/MetaInterface.js +0 -3
- package/dist/interfaces/MetaInterface.js.map +0 -1
- package/dist/interfaces/OptionInterface.d.ts +0 -25
- package/dist/interfaces/OptionInterface.d.ts.map +0 -1
- package/dist/interfaces/OptionInterface.js +0 -3
- package/dist/interfaces/OptionInterface.js.map +0 -1
- package/docs/demo.wav +0 -0
- package/docs/index.html +0 -365
- package/docs/localaudio.html +0 -718
- package/docs/reverb.js +0 -432
- package/docs/reverb.js.map +0 -1
- package/src/Meta.ts +0 -8
- package/src/NoiseType.ts +0 -7
- package/src/Reverb.ts +0 -366
- package/tsconfig.json +0 -32
- package/webpack.config.ts +0 -102
package/src/Reverb.ts
DELETED
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
import Meta from './Meta';
|
|
2
|
-
import OptionInterface from './interfaces/OptionInterface';
|
|
3
|
-
import {NoiseType} from './NoiseType';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* JS reverb effect class
|
|
7
|
-
*
|
|
8
|
-
* @author Logue <logue@hotmail.co.jp>
|
|
9
|
-
* @copyright 2019-2021 Masashi Yoshikawa <https://logue.dev/> All rights reserved.
|
|
10
|
-
* @license MIT
|
|
11
|
-
* @see {@link https://github.com/logue/Reverb.js}
|
|
12
|
-
* {@link https://github.com/web-audio-components/simple-reverb}
|
|
13
|
-
*/
|
|
14
|
-
export default class Reverb {
|
|
15
|
-
/** Version strings */
|
|
16
|
-
public readonly version: string;
|
|
17
|
-
/** Build date */
|
|
18
|
-
public readonly build: string;
|
|
19
|
-
/** AudioContext */
|
|
20
|
-
private readonly ctx: AudioContext;
|
|
21
|
-
/** Wet Level (Reverberated node) */
|
|
22
|
-
private readonly wetGainNode: GainNode;
|
|
23
|
-
/** Dry Level (Original sound node) */
|
|
24
|
-
private readonly dryGainNode: GainNode;
|
|
25
|
-
/** Impulse response filter */
|
|
26
|
-
private readonly filterNode: BiquadFilterNode;
|
|
27
|
-
/** Convolution node for applying impulse response */
|
|
28
|
-
private readonly convolverNode: ConvolverNode;
|
|
29
|
-
/** Output nodse */
|
|
30
|
-
private readonly outputNode: GainNode;
|
|
31
|
-
/** Option */
|
|
32
|
-
private readonly _options: OptionInterface;
|
|
33
|
-
/** Connected flag */
|
|
34
|
-
private isConnected: boolean;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* constructor
|
|
38
|
-
* @param ctx Root AudioContext
|
|
39
|
-
* @param options Configure
|
|
40
|
-
*/
|
|
41
|
-
constructor(ctx: AudioContext, options: OptionInterface | undefined) {
|
|
42
|
-
// バージョン情報など
|
|
43
|
-
this.version = Meta.version;
|
|
44
|
-
this.build = Meta.date;
|
|
45
|
-
// マスターのAudioContextを取得
|
|
46
|
-
this.ctx = ctx;
|
|
47
|
-
// デフォルト値をマージ
|
|
48
|
-
this._options = {...optionDefaults, ...options} as const;
|
|
49
|
-
// 初期化
|
|
50
|
-
this.wetGainNode = this.ctx.createGain();
|
|
51
|
-
this.dryGainNode = this.ctx.createGain();
|
|
52
|
-
this.filterNode = this.ctx.createBiquadFilter();
|
|
53
|
-
this.convolverNode = this.ctx.createConvolver();
|
|
54
|
-
this.outputNode = this.ctx.createGain();
|
|
55
|
-
// 接続済みフラグを落とす
|
|
56
|
-
this.isConnected = false;
|
|
57
|
-
// インパルス応答を生成
|
|
58
|
-
this.buildImpulse();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Connect the node for the reverb effect to the original sound node.
|
|
63
|
-
* @param sourceNode Input source node
|
|
64
|
-
*/
|
|
65
|
-
public connect(sourceNode: AudioNode): AudioNode {
|
|
66
|
-
if (this.isConnected) {
|
|
67
|
-
// 接続済みだった場合そのまま出力ノードを返す
|
|
68
|
-
return this.outputNode;
|
|
69
|
-
}
|
|
70
|
-
// 畳み込みノードをウェットレベルに接続
|
|
71
|
-
this.convolverNode.connect(this.filterNode);
|
|
72
|
-
// フィルタノードをウェットレベルに接続
|
|
73
|
-
this.filterNode.connect(this.wetGainNode);
|
|
74
|
-
// 入力ノードを畳み込みノードに接続
|
|
75
|
-
sourceNode.connect(this.convolverNode);
|
|
76
|
-
// ドライレベルを出力ノードに接続
|
|
77
|
-
sourceNode.connect(this.dryGainNode).connect(this.outputNode);
|
|
78
|
-
// ウェットレベルを出力ノードに接続
|
|
79
|
-
sourceNode.connect(this.wetGainNode).connect(this.outputNode);
|
|
80
|
-
// トライ/ウェットノードの量を調整
|
|
81
|
-
this.mix(this._options.mix);
|
|
82
|
-
// 接続済みフラグを立てる
|
|
83
|
-
this.isConnected = true;
|
|
84
|
-
|
|
85
|
-
return this.outputNode;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Disconnect the reverb node
|
|
90
|
-
* @param sourceNode Input source node
|
|
91
|
-
*/
|
|
92
|
-
public disconnect(sourceNode: AudioNode | undefined): AudioNode | undefined {
|
|
93
|
-
// 初期状態ではノードがつながっていないためエラーになる
|
|
94
|
-
if (this.isConnected) {
|
|
95
|
-
// 畳み込みノードをウェットレベルから切断
|
|
96
|
-
this.convolverNode.disconnect(this.filterNode);
|
|
97
|
-
// フィルタノードをウェットレベルから切断
|
|
98
|
-
this.filterNode.disconnect(this.wetGainNode);
|
|
99
|
-
}
|
|
100
|
-
// 接続済みフラグを解除
|
|
101
|
-
this.isConnected = false;
|
|
102
|
-
|
|
103
|
-
// そのままノードを返す(他のAPIに似せるため)
|
|
104
|
-
return sourceNode;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Dry/Wet ratio
|
|
109
|
-
* @param mix
|
|
110
|
-
*/
|
|
111
|
-
public mix(mix: number): void {
|
|
112
|
-
if (!this.inRange(mix, 0, 1)) {
|
|
113
|
-
throw new RangeError('Reverb.js: Dry/Wet ratio must be between 0 to 1.');
|
|
114
|
-
}
|
|
115
|
-
this._options.mix = mix;
|
|
116
|
-
this.dryGainNode.gain.value = 1 - this._options.mix;
|
|
117
|
-
this.wetGainNode.gain.value = this._options.mix;
|
|
118
|
-
console.debug(`Reverb.js: Set dry/wet ratio to ${mix * 100}%`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Set Impulse Response time length (second)
|
|
123
|
-
* @param value
|
|
124
|
-
*/
|
|
125
|
-
public time(value: number): void {
|
|
126
|
-
if (!this.inRange(value, 1, 50)) {
|
|
127
|
-
throw new RangeError(
|
|
128
|
-
'Reverb.js: Time length of inpulse response must be less than 50sec.'
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
this._options.time = value;
|
|
132
|
-
this.buildImpulse();
|
|
133
|
-
console.info(`Reverb.js: Set inpulse response time length to ${value}sec.`);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Impulse response decay rate.
|
|
138
|
-
* @param value
|
|
139
|
-
*/
|
|
140
|
-
public decay(value: number): void {
|
|
141
|
-
if (!this.inRange(value, 0, 100)) {
|
|
142
|
-
throw new RangeError(
|
|
143
|
-
'Reverb.js: Inpulse Response decay level must be less than 100.'
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
this._options.decay = value;
|
|
147
|
-
this.buildImpulse();
|
|
148
|
-
console.debug(`Reverb.js: Set inpulse response decay level to ${value}.`);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Delay before reverberation starts
|
|
153
|
-
* @param value time[ms]
|
|
154
|
-
*/
|
|
155
|
-
public delay(value: number): void {
|
|
156
|
-
if (!this.inRange(value, 0, 100)) {
|
|
157
|
-
throw new RangeError(
|
|
158
|
-
'Reverb.js: Inpulse Response delay time must be less than 100.'
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
this._options.delay = value;
|
|
162
|
-
this.buildImpulse();
|
|
163
|
-
console.debug(`Reverb.js: Set inpulse response delay time to ${value}sec.`);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Reverse the impulse response.
|
|
168
|
-
* @param reverse
|
|
169
|
-
*/
|
|
170
|
-
public reverse(reverse: boolean): void {
|
|
171
|
-
this._options.reverse = reverse;
|
|
172
|
-
this.buildImpulse();
|
|
173
|
-
console.debug(
|
|
174
|
-
`Reverb.js: Inpulse response is ${reverse ? '' : 'not '}reversed.`
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Filter for impulse response
|
|
180
|
-
* @param type
|
|
181
|
-
*/
|
|
182
|
-
public filterType(type: BiquadFilterType): void {
|
|
183
|
-
this.filterNode.type = this._options.filterType = type;
|
|
184
|
-
console.debug(`Set filter type to ${type}`);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Filter frequency applied to impulse response
|
|
189
|
-
* @param freq
|
|
190
|
-
*/
|
|
191
|
-
public filterFreq(freq: number): void {
|
|
192
|
-
if (!this.inRange(freq, 20, 5000)) {
|
|
193
|
-
throw new RangeError(
|
|
194
|
-
'Reverb.js: Filter frequrncy must be between 20 and 5000.'
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
this._options.filterFreq = freq;
|
|
198
|
-
this.filterNode.frequency.value = this._options.filterFreq;
|
|
199
|
-
console.debug(`Set filter frequency to ${freq}Hz.`);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Filter quality.
|
|
204
|
-
* @param q
|
|
205
|
-
*/
|
|
206
|
-
public filterQ(q: number): void {
|
|
207
|
-
if (!this.inRange(q, 0, 10)) {
|
|
208
|
-
throw new RangeError(
|
|
209
|
-
'Reverb.js: Filter quality value must be between 0 and 10.'
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
this._options.filterQ = q;
|
|
213
|
-
this.filterNode.Q.value = this._options.filterQ;
|
|
214
|
-
console.debug(`Set filter quality to ${q}.`);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Inpulse Response Noise algorithm.
|
|
219
|
-
* @param type
|
|
220
|
-
*/
|
|
221
|
-
public setNoise(type: NoiseType) {
|
|
222
|
-
this._options.noise = type;
|
|
223
|
-
this.buildImpulse();
|
|
224
|
-
console.debug(`Set Noise type to ${type}.`);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* return true if in range, otherwise false
|
|
229
|
-
* @private
|
|
230
|
-
* @param x Target value
|
|
231
|
-
* @param min Minimum value
|
|
232
|
-
* @param max Maximum value
|
|
233
|
-
* @return
|
|
234
|
-
*/
|
|
235
|
-
private inRange(x: number, min: number, max: number): boolean {
|
|
236
|
-
return (x - min) * (x - max) <= 0;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Utility function for building an impulse response
|
|
241
|
-
* from the module parameters.
|
|
242
|
-
* @private
|
|
243
|
-
*/
|
|
244
|
-
private buildImpulse(): void {
|
|
245
|
-
// インパルス応答生成ロジック
|
|
246
|
-
|
|
247
|
-
/** サンプリングレート */
|
|
248
|
-
const rate: number = this.ctx.sampleRate;
|
|
249
|
-
/** インパルス応答の演奏時間 */
|
|
250
|
-
const duration: number = Math.max(rate * this._options.time, 1);
|
|
251
|
-
/** インパルス応答が始まるまでの遅延時間 */
|
|
252
|
-
const delayDuration: number = rate * this._options.delay;
|
|
253
|
-
/** インパルス応答バッファ(今の所ステレオのみ) */
|
|
254
|
-
const impulse: AudioBuffer = this.ctx.createBuffer(2, duration, rate);
|
|
255
|
-
/** 左チャンネル */
|
|
256
|
-
const impulseL: Float32Array = new Float32Array(duration);
|
|
257
|
-
/** 右チャンネル*/
|
|
258
|
-
const impulseR: Float32Array = new Float32Array(duration);
|
|
259
|
-
|
|
260
|
-
/** 一時計算用 */
|
|
261
|
-
const b = [0, 0, 0, 0, 0, 0, 0];
|
|
262
|
-
|
|
263
|
-
for (let i = 0; i < duration; i++) {
|
|
264
|
-
/** @type {number} 減衰率 */
|
|
265
|
-
let n = 0;
|
|
266
|
-
|
|
267
|
-
if (i < delayDuration) {
|
|
268
|
-
// Delay Effect
|
|
269
|
-
impulseL[i] = 0;
|
|
270
|
-
impulseR[i] = 0;
|
|
271
|
-
n = this._options.reverse
|
|
272
|
-
? duration - (i - delayDuration)
|
|
273
|
-
: i - delayDuration;
|
|
274
|
-
} else {
|
|
275
|
-
n = this._options.reverse ? duration - i : i;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
switch (this._options.noise) {
|
|
279
|
-
default:
|
|
280
|
-
case NoiseType.WHITE:
|
|
281
|
-
// White Noise
|
|
282
|
-
impulseL[i] = Reverb.whiteNoise();
|
|
283
|
-
impulseR[i] = Reverb.whiteNoise();
|
|
284
|
-
break;
|
|
285
|
-
case NoiseType.PINK:
|
|
286
|
-
// ピンクノイズ生成処理
|
|
287
|
-
// http://noisehack.com/generate-noise-web-audio-api/
|
|
288
|
-
b[0] = 0.99886 * b[0] + Reverb.whiteNoise() * 0.0555179;
|
|
289
|
-
b[1] = 0.99332 * b[1] + Reverb.whiteNoise() * 0.0750759;
|
|
290
|
-
b[2] = 0.969 * b[2] + Reverb.whiteNoise() * 0.153852;
|
|
291
|
-
b[3] = 0.8665 * b[3] + Reverb.whiteNoise() * 0.3104856;
|
|
292
|
-
b[4] = 0.55 * b[4] + Reverb.whiteNoise() * 0.5329522;
|
|
293
|
-
b[5] = -0.7616 * b[5] - Reverb.whiteNoise() * 0.016898;
|
|
294
|
-
|
|
295
|
-
impulseL[i] =
|
|
296
|
-
b[0] +
|
|
297
|
-
b[1] +
|
|
298
|
-
b[2] +
|
|
299
|
-
b[3] +
|
|
300
|
-
b[4] +
|
|
301
|
-
b[5] +
|
|
302
|
-
b[6] +
|
|
303
|
-
Reverb.whiteNoise() * 0.5362;
|
|
304
|
-
|
|
305
|
-
impulseR[i] =
|
|
306
|
-
b[0] +
|
|
307
|
-
b[1] +
|
|
308
|
-
b[2] +
|
|
309
|
-
b[3] +
|
|
310
|
-
b[4] +
|
|
311
|
-
b[5] +
|
|
312
|
-
b[6] +
|
|
313
|
-
Reverb.whiteNoise() * 0.5362;
|
|
314
|
-
|
|
315
|
-
// ゲイン補償処理
|
|
316
|
-
impulseL[i] *= 0.11;
|
|
317
|
-
impulseR[i] *= 0.11;
|
|
318
|
-
|
|
319
|
-
b[6] = Reverb.whiteNoise() * 0.115926;
|
|
320
|
-
break;
|
|
321
|
-
case NoiseType.BROWN:
|
|
322
|
-
// ブラウンノイズ生成処理
|
|
323
|
-
impulseL[i] = (b[0] + 0.02 * Reverb.whiteNoise()) / 1.02;
|
|
324
|
-
b[0] = impulseL[i];
|
|
325
|
-
impulseR[i] = (b[1] + 0.02 * Reverb.whiteNoise()) / 1.02;
|
|
326
|
-
b[1] = impulseR[i];
|
|
327
|
-
|
|
328
|
-
// ゲイン補償処理
|
|
329
|
-
impulseL[i] *= 3.5;
|
|
330
|
-
impulseR[i] *= 3.5;
|
|
331
|
-
break;
|
|
332
|
-
}
|
|
333
|
-
// 音を減衰させる
|
|
334
|
-
impulseL[i] *= (1 - n / duration) ** this._options.decay;
|
|
335
|
-
impulseR[i] *= (1 - n / duration) ** this._options.decay;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// インパルス応答のバッファに生成したWaveTableを代入
|
|
339
|
-
impulse.getChannelData(0).set(impulseL);
|
|
340
|
-
impulse.getChannelData(1).set(impulseR);
|
|
341
|
-
|
|
342
|
-
this.convolverNode.buffer = impulse;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Generate white noise
|
|
346
|
-
*/
|
|
347
|
-
private static whiteNoise(): number {
|
|
348
|
-
// TODO: この乱数は本当に偏り無いのだろうか?
|
|
349
|
-
return Math.random() * 2 - 1;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* デフォルト値
|
|
355
|
-
*/
|
|
356
|
-
const optionDefaults: OptionInterface = {
|
|
357
|
-
noise: NoiseType.WHITE,
|
|
358
|
-
decay: 2,
|
|
359
|
-
delay: 0,
|
|
360
|
-
reverse: false,
|
|
361
|
-
time: 1.1,
|
|
362
|
-
filterType: 'lowpass',
|
|
363
|
-
filterFreq: 2200,
|
|
364
|
-
filterQ: 1,
|
|
365
|
-
mix: 0.5,
|
|
366
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/tsconfig.json",
|
|
3
|
-
"extends": "./node_modules/gts/tsconfig-google.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"declarationMap": true,
|
|
7
|
-
"module": "commonjs",
|
|
8
|
-
"outDir": "dist",
|
|
9
|
-
"sourceMap": true,
|
|
10
|
-
"lib": [
|
|
11
|
-
"dom"
|
|
12
|
-
],
|
|
13
|
-
"target": "esnext",
|
|
14
|
-
/* Checks */
|
|
15
|
-
"strict": true,
|
|
16
|
-
"noUnusedLocals": true,
|
|
17
|
-
"noUnusedParameters": true,
|
|
18
|
-
"noImplicitReturns": true,
|
|
19
|
-
"noFallthroughCasesInSwitch": true,
|
|
20
|
-
"moduleResolution": "node",
|
|
21
|
-
"esModuleInterop": true,
|
|
22
|
-
"skipLibCheck": true,
|
|
23
|
-
"forceConsistentCasingInFileNames": true
|
|
24
|
-
},
|
|
25
|
-
"files": [
|
|
26
|
-
"src/Reverb.ts"
|
|
27
|
-
],
|
|
28
|
-
"include": [
|
|
29
|
-
"src/**/*.ts",
|
|
30
|
-
"test/**/*.ts"
|
|
31
|
-
]
|
|
32
|
-
}
|
package/webpack.config.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import webpack = require('webpack');
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import * as fs from 'fs';
|
|
5
|
-
import TerserPlugin from 'terser-webpack-plugin';
|
|
6
|
-
import WebpackDevServer from 'webpack-dev-server';
|
|
7
|
-
|
|
8
|
-
declare module 'webpack' {
|
|
9
|
-
interface Configuration {
|
|
10
|
-
/**
|
|
11
|
-
* Can be used to configure the behaviour of webpack-dev-server when
|
|
12
|
-
* the webpack config is passed to webpack-dev-server CLI.
|
|
13
|
-
*/
|
|
14
|
-
devServer?: WebpackDevServer.Configuration;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// バージョン情報など
|
|
19
|
-
const pjson = require('./package.json');
|
|
20
|
-
// 現在の時刻(ビルド時刻)
|
|
21
|
-
const build: string = new Date().toISOString();
|
|
22
|
-
|
|
23
|
-
module.exports = (_env: any, argv: any): webpack.Configuration => {
|
|
24
|
-
const isProduction: boolean = argv.mode === 'production';
|
|
25
|
-
if (isProduction) {
|
|
26
|
-
// Meta.tsを書き込む
|
|
27
|
-
fs.writeFileSync(
|
|
28
|
-
path.resolve(path.join(__dirname, 'src/Meta.ts')),
|
|
29
|
-
`import MetaInterface from './interfaces/MetaInterface';
|
|
30
|
-
|
|
31
|
-
// This file is auto-generated by the build system.
|
|
32
|
-
const meta: MetaInterface = {
|
|
33
|
-
version: '${pjson.version}',
|
|
34
|
-
date: '${build}',
|
|
35
|
-
};
|
|
36
|
-
export default meta;
|
|
37
|
-
`
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
const banner = `${pjson.name} v${pjson.version} | ${pjson.author.name} | license: ${pjson.license} | build: ${build}`;
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
mode: isProduction ? 'production' : 'development',
|
|
44
|
-
target: 'node',
|
|
45
|
-
devtool: !isProduction ? 'source-map' : false,
|
|
46
|
-
devServer: {
|
|
47
|
-
static: {
|
|
48
|
-
directory: 'docs',
|
|
49
|
-
watch: true,
|
|
50
|
-
},
|
|
51
|
-
open: false,
|
|
52
|
-
hot: false,
|
|
53
|
-
},
|
|
54
|
-
entry: {
|
|
55
|
-
reverb: './src/Reverb.ts',
|
|
56
|
-
},
|
|
57
|
-
output: {
|
|
58
|
-
path: path.resolve(__dirname, 'bin'),
|
|
59
|
-
filename: !isProduction ? '[name].js' : '[name].min.js',
|
|
60
|
-
library: 'Reverb',
|
|
61
|
-
libraryTarget: 'umd',
|
|
62
|
-
umdNamedDefine: true,
|
|
63
|
-
globalObject: "(typeof self !== 'undefined' ? self : this)",
|
|
64
|
-
},
|
|
65
|
-
optimization: {
|
|
66
|
-
minimize: isProduction,
|
|
67
|
-
minimizer: [
|
|
68
|
-
new TerserPlugin({
|
|
69
|
-
terserOptions: {
|
|
70
|
-
ecma: 2020,
|
|
71
|
-
compress: {drop_console: true},
|
|
72
|
-
output: {
|
|
73
|
-
comments: false,
|
|
74
|
-
beautify: false,
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
}),
|
|
78
|
-
],
|
|
79
|
-
splitChunks: {
|
|
80
|
-
minSize: 0,
|
|
81
|
-
},
|
|
82
|
-
concatenateModules: false,
|
|
83
|
-
},
|
|
84
|
-
module: {
|
|
85
|
-
rules: [
|
|
86
|
-
{
|
|
87
|
-
test: /\.tsx?$/,
|
|
88
|
-
loader: 'ts-loader',
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
},
|
|
92
|
-
resolve: {
|
|
93
|
-
modules: [`${__dirname}/src`, 'node_modules'],
|
|
94
|
-
extensions: ['webpack.ts', '.ts', '.tsx'],
|
|
95
|
-
},
|
|
96
|
-
plugins: [
|
|
97
|
-
new webpack.BannerPlugin({
|
|
98
|
-
banner: banner,
|
|
99
|
-
}),
|
|
100
|
-
],
|
|
101
|
-
};
|
|
102
|
-
};
|