Skip to content
Snippets Groups Projects
webpack.config.ts 2.18 KiB
import path from "path";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";

import { Configuration as WebpackConfiguration } from "webpack";
import { Configuration as WebpackDevServerConfiguration } from "webpack-dev-server";

interface Configuration extends WebpackConfiguration {
  devServer?: WebpackDevServerConfiguration;
}

const config: Configuration = {
  entry: "./src/index.tsx",
  module: {
    rules: [
      {
        test: /\.(ts|js)x?$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: [
              "@babel/preset-env",
              "@babel/preset-react",
              "@babel/preset-typescript",
            ],
          },
        },
      },
      {
        test: /\.scss$/,
        exclude: /node_modules/,
        use: [
          { loader: "style-loader" },
          { loader: "css-loader" },
          { loader: "sass-loader" },
        ],
      },
      {
        test: /\.css$/,
        use: [{ loader: "style-loader" }, { loader: "css-loader" }],
      },
      {
        test: /\.(png|svg|jpe?g|gif)$/,
        type: 'asset/resource'
      },
    ],
  },
  resolve: {
    extensions: [".tsx", ".ts", ".js", ".html", '.svg'],
    alias: {
      shared: path.resolve(__dirname, '../compendium-frontend/src/shared/'),
      react: path.resolve('./node_modules/react'), // necessary to prevent react from being loaded twice in shared components
    },
  },
  output: {
    path: path.resolve(__dirname, "..", "compendium_v2", "static"),
    filename: "survey-bundle.js",
  },
  devServer: {
    static: path.resolve(__dirname, "..", "survey-frontend", "static"),
    compress: true,
    open: ["http://localhost:4001/survey"],
    port: 4001,
    // Allow SPA urls to work with dev-server
    historyApiFallback: true,
    proxy: {
      "/api": "http://127.0.0.1:5000",
      "/login": "http://127.0.0.1:5000",
      "/logout": "http://127.0.0.1:5000",
      "/authorize": "http://127.0.0.1:5000",
    },
  },
  devtool: process.env.NODE_ENV === "production" ? undefined : "inline-source-map",
  plugins: [
    new ForkTsCheckerWebpackPlugin({
      async: false,
    }),
  ],
};

export default config;