forked from mudcube/MIDI.js
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathwebpack.config.js
More file actions
97 lines (91 loc) · 3.55 KB
/
webpack.config.js
File metadata and controls
97 lines (91 loc) · 3.55 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
// MIDICube main Webpack config.
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const ESLintPlugin = require('eslint-webpack-plugin');
const PACKAGE = require('./package.json');
const TerserPlugin = require('terser-webpack-plugin');
const version = PACKAGE.version;
const date_now = new Date().toISOString().replace(/T.*/, '');
const indexJs = fs.readFileSync('./js/index.js', 'utf8');
const match = indexJs.match(/\/\*!([\s\S]*?)\*\//);
const extractedBanner = match ? match[1].trim() : '';
const BANNER = `
midicube ${version} built on ${date_now}.
${extractedBanner}
`;
module.exports = env => {
const mode = env.development ? 'development' : 'production';
const filename = (mode === 'production') ? 'midicube.js' : 'midicube.dev.js';
const config = {
entry: './js/index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename,
library: 'MIDI',
libraryTarget: 'umd',
umdNamedDefine: true,
},
mode,
devtool: 'source-map',
// mode: 'development',
// devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.js?$/,
exclude: /(node_modules|bower_components|soundfont|soundfonts)/,
use: [{
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env',
{
// do not transform modules; let webpack do it
modules: false,
useBuiltIns: 'usage',
corejs: 3,
targets: {
browsers: [
'last 3 years',
'not < 0.04% in US',
'not android < 80', // bug in browserslist
'not ios <= 10',
'not samsung <= 4',
'not ie <= 12', // all versions -- edge is separate
],
},
}
],
],
plugins: [
'@babel/plugin-transform-object-assign',
'@babel/plugin-transform-export-namespace-from',
],
},
}],
},
],
},
optimization: {
minimize: (mode === 'production'),
minimizer: [
new TerserPlugin({
extractComments: false, // Disable moving comments to .LICENSE.txt
terserOptions: {
format: {
comments: /^!/, // Keep comments that start with /*! (e.g., your banner)
},
},
}),
],
},
plugins: [
new webpack.BannerPlugin({banner: BANNER.trim()}),
new ESLintPlugin({
failOnError: (mode === 'production'),
}),
],
};
return config;
};