aboutsummaryrefslogtreecommitdiff
path: root/webpack.config.js
blob: d86379d57f26b956c4fc7b55db27e5d3a63534b6 (plain)
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
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');


module.exports = function (env) {
  env = env || {};
  const base = {
    output: {
      filename: '[name]-bundle.js',
      chunkFilename: "[id].chunk.js",
      path: path.resolve(__dirname, "dist"),
    },
    module: {
      noParse: /taler-emscripten-lib/,
      rules: [
        {
          test: /\.tsx?$/,
          loader: 'ts-loader',
          exclude: /node_modules/,
          exclude: /taler-emscripten-lib/,
        }
      ]
    },
    resolve: {
      modules: [path.resolve(__dirname, "./"), "node_modules"],
      extensions: [".tsx", ".ts", ".js"]
    },
    plugins: [],
    devtool: "source-map",
    externals: ["fs", "path", "child_process", /.*taler-emscripten-lib.*/],
  }
  if (env.prod) {
    base.plugins.push(new webpack.optimize.UglifyJsPlugin());
    base.plugins.push(new webpack.LoaderOptionsPlugin({minimize: true}));
    base.plugins.push(new webpack.DefinePlugin({
      "process.env.NODE_ENV": JSON.stringify("production")
    }));
  }
  const configWebWorker = {
    entry: {"cryptoWorker": "./src/crypto/cryptoWorker.ts"},
    target: "webworker",
  };

  const configBackground = {
    entry: {"background": "./src/webex/background.ts"},
  };

  const configContentScript = {
    entry: {"contentScript": "./src/webex/notify.ts"},
  };

  const configExtensionPages = {
    entry: {
      "add-auditor": "./src/webex/pages/add-auditor.tsx",
      "auditors": "./src/webex/pages/auditors.tsx",
      "confirm-contract": "./src/webex/pages/confirm-contract.tsx",
      "confirm-create-reserve": "./src/webex/pages/confirm-create-reserve.tsx",
      "error": "./src/webex/pages/error.tsx",
      "logs": "./src/webex/pages/logs.tsx",
      "popup": "./src/webex/pages/popup.tsx",
      "show-db": "./src/webex/pages/show-db.ts",
      "tree": "./src/webex/pages/tree.tsx",
      "payback": "./src/webex/pages/payback.tsx",
    },
    plugins: [
      new webpack.optimize.CommonsChunkPlugin({
        name: "page-common",
        minChunks: 2,
      }),
    ],
  };

  return [
    merge(base, configBackground),
    merge(base, configWebWorker),
    merge(base, configExtensionPages),
    merge(base, configContentScript)
  ];
}