Merge pull request #2891 from solgenomics/topic/ona_bugs_fix
[sgn.git] / js / build.webpack.config.js
blob3510ed485242c69ccbf82e15bbee002ade035cc4
1 const path = require('path');
2 const glob = require("glob");
3 const filemap = require(path.resolve(__dirname,"./webpack_util/webpack-filemap-plugin.js"));
4 const UglifyWebpackPlugin = require("uglifyjs-webpack-plugin");
6 const sourcePath = path.resolve(__dirname, "source");
7 const entryPath = path.resolve(sourcePath, "entries");
8 const legacyPath = path.resolve(sourcePath, "legacy");
10 module.exports = {
11     mode: "production",
12     target: 'web',
13     entry: (() => {
14         var entries = {};
15         glob.sync(path.resolve(entryPath, "**/*.js")).forEach(val => {
16             var prekey = val.replace(entryPath+"/","");
17             var key = prekey.match(/(.*)\.js$/)[1];
18             entries[key] = val;
19         });
20         return entries;
21     })(),
22     // Give entries a common library name
23     output: {
24         path: path.resolve(__dirname, "build/"),
25         publicPath: '/js',
26         filename: '[name].min.js',
27         chunkFilename: `chunk.[chunkhash].js`,
28         library: ["jsMod","[name]"],
29         libraryTarget: "umd"
30     },
31     // Set up babel and JSAN processing
32     module: {
33         rules: [
34             {
35                 test: /\.js$/,
36                 exclude: /(node_modules|bower_components)/,
37                 use: [{
38                     loader: 'babel-loader',
39                     options: {
40                         sourceType: "unambiguous",
41                         presets: [['@babel/preset-env',{
42                           useBuiltIns: 'usage'
43                         }]]
44                     }
45                 },{
46                     loader: path.resolve(__dirname,"./webpack_util/jsan-preprocess-loader.js"),
47                     options:{'legacyPath':legacyPath}
48                 }]
49             },
50             {
51                 test: legacyPath,
52                 use: [{
53                     loader: path.resolve(__dirname,"./webpack_util/jsan-error-loader.js")
54                 }]
55             }
56         ]
57     },
58     // Chunks and Minimization settings
59     optimization: {
60         minimize: true,
61         namedChunks: true,
62         minimizer: [new UglifyWebpackPlugin({ 
63             'sourceMap': true,
64             'parallel': 4,
65             
66         })],
67         runtimeChunk: {
68             name: 'runtime'
69         },
70         splitChunks: {
71             cacheGroups: {
72                 default: false,
73                 shared: {
74                     minChunks: 2,
75                     test: sourcePath,
76                     chunks: "initial",
77                     minSize: 1000
78                 },
79                 jsan: {
80                     minChunks: 2,
81                     test: path.resolve(__dirname, "webpack_util/adaptor.js"),
82                     chunks: "all",
83                     minSize: 1000
84                 },
85                 async: {
86                     minChunks: 2,
87                     test: sourcePath,
88                     chunks: "async",
89                     minSize: 1000
90                 }
91             }
92         }
93     },
94     devtool: "source-map",
95     plugins: [new filemap({'legacy_regex':"./webpack_util/dependency.regex"})]