aboutsummaryrefslogtreecommitdiff
path: root/webpack.config.js
blob: 7194b4fc45b9e4c71f02e1194988074714496fe3 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* eslint-env node */

const path = require("path");
const dotenv = require("dotenv");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const WorkboxPlugin = require("workbox-webpack-plugin");
const glob = require("glob");

// this will update the process.env with environment variables in .env file
dotenv.config();

module.exports = {
  entry: {
    ui: "./webAO/ui.js",
    client: "./webAO/client.ts",
    master: "./webAO/master.ts",
    dom: {
      dependOn: "client",
      import: glob.sync("./webAO/dom/*.{js,ts}", { "dotRelative": true }),
    },
    components: glob.sync("./webAO/components/*.js", { "dotRelative": true }),
  },
  node: {
    global: true,
  },
  devtool: "source-map",
  resolve: {
    extensions: [".js", ".jsx", ".tsx", ".ts", ".json"],
  },
  devServer: {
    static: {
      directory: path.join(__dirname, "webAO"),
    },
    compress: true,
    port: 8080,
    allowedHosts: "all",
  },
  mode: "production",
  module: {
    rules: [
      {
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: "babel-loader",
          options: {
            presets: [
              [
                "@babel/preset-env",
                {
                  useBuiltIns: "usage",
                  targets: [
                    "defaults",
                    "Safari > 3",
                    "Opera > 8",
                    "Android > 3",
                  ],
                  corejs: 3,
                },
              ],
            ],
          },
        },
      },
      {
        test: /\.ts$/,
        loader: "esbuild-loader",
        options: { loader: "ts" }
      },
      // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
      { test: /\.js$/, loader: "source-map-loader" },
    ],
  },
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].[contenthash].bundle.js",
    clean: true,
  },
  performance: {
    hints: false,
    maxEntrypointSize: 512000,
    maxAssetSize: 512000,
  },
  plugins: [
    new CopyPlugin({
      patterns: [
        { from: path.resolve(__dirname, "webAO", "styles"), to: "styles" },
        { from: path.resolve(__dirname, "static") },
        { from: path.resolve(__dirname, "webAO", "golden"), to: "golden" },
        { from: path.resolve(__dirname, "webAO", "lib"), to: "lib" },
      ],
    }),
    new HtmlWebpackPlugin({
      filename: "index.html",
      template: "public/index.html",
      chunks: ["master", "sw"],
      title: "Attorney Online",
    }),

    new HtmlWebpackPlugin({
      title: "Attorney Online",
      filename: "client.html",
      chunks: ["client", "ui", "dom", "components"],
      template: "public/client.html",
    }),
    new webpack.DefinePlugin({
      "process.env": JSON.stringify(process.env),
    }),
    // new WorkboxPlugin.GenerateSW(),
  ],
};