Skip to content

Commit 8b5bba3

Browse files
authored
Merge pull request #630 from 8633brown/webpack
simplify the webpack config
2 parents 058dbbf + 227b726 commit 8b5bba3

10 files changed

+81
-146
lines changed

Diff for: build-utils/loadPresets.js

-14
This file was deleted.

Diff for: build-utils/presets/webpack.analyze.js

-6
This file was deleted.

Diff for: build-utils/presets/webpack.optimize.js

-30
This file was deleted.

Diff for: build-utils/webpack.development.js

-15
This file was deleted.

Diff for: build-utils/webpack.production.js

-36
This file was deleted.

Diff for: index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require('./static-wrappers/license')
12
var version = require('./version');
23
var animation = require('./src/api/abc_animation');
34
var tuneBook = require('./src/api/abc_tunebook');

Diff for: package.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
"types": "types/index.d.ts",
77
"scripts": {
88
"webpack": "webpack",
9-
"build": "npm run build:basic && npm run build:basic-min && npm run build:plugin",
10-
"build:basic": "npm run webpack -- --env.mode development --env.type basic -o dist/abcjs-basic.js",
11-
"build:basic-min": "npm run webpack -- --env.mode production --env.type basic",
12-
"build:plugin": "npm run webpack -- --env.mode production --env.type plugin",
9+
"build": "npm run fix-versions && npm run build:basic && npm run webpack && npm run copy-output",
10+
"build:basic": "npm run webpack -- --mode development --config-name basic",
11+
"build:basic-min": "npm run webpack -- --mode production --config-name basic",
12+
"build:plugin": "npm run webpack -- --mode production --config-name plugin",
13+
"build:midi": "npm run webpack -- --mode production --config-name midi",
14+
"fix-versions": "./fix-versions.sh 6.0.0-beta.28",
15+
"copy-output": "./build-copy.sh 6.0.0-beta.28",
1316
"test": "mocha 'tests/**/*.js'",
1417
"docs:dev": "vuepress dev docs",
1518
"docs:build": "vuepress build docs",
16-
"build:analyze": "npm run build:basic -- --env.presets analyze"
19+
"build:analyze": "npm run build:basic -- --env.analyze"
1720
},
1821
"repository": {
1922
"type": "git",
@@ -49,6 +52,7 @@
4952
"babel-loader": "8.1.0",
5053
"chai": "4.2.0",
5154
"compression-webpack-plugin": "5.0.1",
55+
"midi": "https://github.com/paulrosen/MIDI.js.git#abcjs",
5256
"mocha": "8.1.3",
5357
"serialize-javascript": "4.0.0",
5458
"svg-inline-loader": "0.8.2",

Diff for: static-wrappers/basic.js

-2
This file was deleted.

Diff for: static-wrappers/midi.js

-2
This file was deleted.

Diff for: webpack.config.js

+71-36
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,73 @@
1-
const {merge} = require("webpack-merge");
2-
const modeConfig = env => require(`./build-utils/webpack.${env.mode}`)(env);
3-
const presetConfig = require("./build-utils/loadPresets");
1+
const pkg = require("./package.json");
2+
const TerserPlugin = require('terser-webpack-plugin');
3+
const WebpackBundleAnalyzer = require("webpack-bundle-analyzer")
4+
.BundleAnalyzerPlugin;
45

5-
module.exports = ({mode, presets, type} = {mode: "production", presets: []}) => {
6-
return merge(
7-
{
8-
entry: `./static-wrappers/${type}.js`,
9-
output: {
10-
library: {
11-
amd: 'abcjs',
12-
root: 'ABCJS',
13-
commonjs: 'abcjs'
14-
},
15-
libraryTarget: 'umd',
16-
globalObject: 'this'
17-
},
18-
mode,
19-
module: {
20-
rules: [
21-
{
22-
test: /\.js$/,
23-
exclude: /node_modules/,
24-
use: "babel-loader"
25-
},
26-
{
27-
test: /\.svg$/,
28-
loader: 'svg-inline-loader'
29-
}
30-
]
31-
},
32-
plugins: [
33-
]
34-
},
35-
modeConfig({mode, type}),
36-
presetConfig({mode, presets, type})
37-
);
6+
module.exports = (env = {} , argv) => {
7+
const defaults = (argv, type) => {
8+
const config = {
9+
output: {
10+
library: {
11+
amd: 'abcjs',
12+
root: 'ABCJS',
13+
commonjs: 'abcjs'
14+
},
15+
libraryTarget: 'umd',
16+
globalObject: 'this',
17+
filename: argv.mode === 'development' ? `abcjs-${type}.js` : `abcjs-${type}-min.js`,
18+
},
19+
devtool: argv.mode === 'development' ? 'source-map' : false,
20+
module: {
21+
rules: [
22+
{
23+
test: /\.js$/,
24+
exclude: /node_modules/,
25+
use: "babel-loader"
26+
}
27+
],
28+
},
29+
mode: 'production',
30+
optimization:{
31+
minimizer: [
32+
new TerserPlugin({
33+
extractComments: {
34+
condition: /^\*\**!/i,
35+
banner: makeBanner(type)
36+
},
37+
}),
38+
],
39+
}
40+
}
41+
42+
if (env.analyze) {
43+
config.plugins = [
44+
new WebpackBundleAnalyzer()
45+
]
46+
}
47+
return config
48+
}
49+
50+
return [
51+
{
52+
name: 'basic',
53+
entry: `./index.js`,
54+
...defaults(argv, 'basic')
55+
}, {
56+
name: 'plugin',
57+
entry: `./static-wrappers/plugin.js`,
58+
...defaults(argv, 'plugin')
59+
}, {
60+
name: 'midi',
61+
entry: `./midi.js`,
62+
...defaults(argv, 'midi')
63+
}
64+
]
3865
};
66+
67+
function makeBanner(type) {
68+
let banner = `abcjs_${type} v${pkg.version} Copyright © 2009-2021 Paul Rosen and Gregory Dyke (https://abcjs.net) */\n`
69+
if (type === 'midi') {
70+
banner += `/*! midi.js Copyright © Michael Deal (http://mudcu.be) */\n`;
71+
}
72+
return banner + `/*! For license information please see abcjs_${type}.LICENSE`;
73+
}

0 commit comments

Comments
 (0)