File size: 1,744 Bytes
af6912c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const pkg = require("./package.json");
const TerserPlugin = require('terser-webpack-plugin');
const WebpackBundleAnalyzer = require("webpack-bundle-analyzer")
  .BundleAnalyzerPlugin;

module.exports = (env = {} , argv) => {
  const defaults = (argv, type) => {
    const config = {
      target: ['web', 'es5'],
      output: {
        library: {
          amd: 'abcjs',
          root: 'ABCJS',
          commonjs: 'abcjs'
        },
        libraryTarget: 'umd',
        globalObject: 'this',
        filename: argv.mode === 'development' ? `abcjs-${type}.js` : `abcjs-${type}-min.js`,
      },
      devtool: argv.mode === 'development' ? 'source-map' : false,
      module: {
        rules: [
          {
            test: /\.js$/,
            exclude: /node_modules/,
            use: "babel-loader"
          }
        ],
      },
      mode: 'production',
      optimization:{
        minimizer: [
          new TerserPlugin({
            extractComments: {
              filename: '[file].LICENSE',
              condition: /^\*\**!/i,
              banner: makeBanner(type)
            },
          }),
        ],
      }
    }

    if (env.analyze) {
      config.plugins = [
        new WebpackBundleAnalyzer({
          analyzerMode: "static"
        })
      ]
    }
    return config
  }

  return [
    {
      name: 'basic',
      entry: `./index.js`,
      ...defaults(argv, 'basic')
    }, {
      name: 'plugin',
      entry: `./plugin.js`,
      ...defaults(argv, 'plugin')
    }
  ]
};

function makeBanner(type) {
  let banner = `abcjs_${type} v${pkg.version} Copyright © 2009-2024 Paul Rosen and Gregory Dyke (https://abcjs.net) */\n`
  return banner + `/*! For license information please see abcjs_${type}.LICENSE`;
}