Merge pull request #5162 from solgenomics/topic/enable_brapi_photo_trait
[sgn.git] / js / build.webpack.config.js
blob8626914bbc5c4d40ae6b5f2e3bc59b00604f86bf
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                                         "corejs": "3"
44                         }]]
45                     }
46                 },{
47                     loader: path.resolve(__dirname,"./webpack_util/jsan-preprocess-loader.js"),
48                     options:{'legacyPath':legacyPath}
49                 }]
50             },
51             {
52                 test: legacyPath,
53                 use: [{
54                     loader: path.resolve(__dirname,"./webpack_util/jsan-error-loader.js")
55                 }]
56             }
57         ]
58     },
59     // Chunks and Minimization settings
60     optimization: {
61         minimize: true,
62         namedChunks: true,
63         minimizer: [new UglifyWebpackPlugin({
64             uglifyOptions: {
65                 output: {
66                     ascii_only: true
67                 },
68             },
69             'sourceMap': true,
70             'parallel': 4,
71         })],
72         runtimeChunk: {
73             name: 'runtime'
74         },
75         splitChunks: {
76             cacheGroups: {
77                 default: false,
78                 shared: {
79                     minChunks: 2,
80                     test: sourcePath,
81                     chunks: "initial",
82                     minSize: 1000
83                 },
84                 jsan: {
85                     minChunks: 2,
86                     test: path.resolve(__dirname, "webpack_util/adaptor.js"),
87                     chunks: "all",
88                     minSize: 1000
89                 },
90                 async: {
91                     minChunks: 2,
92                     test: sourcePath,
93                     chunks: "async",
94                     minSize: 1000
95                 }
96             }
97         }
98     },
99     devtool: "source-map",
100     plugins: [new filemap({'legacy_regex':"./webpack_util/dependency.regex"})]