| const webpack = require('webpack'); |
| const HtmlWebpackPlugin = require('html-webpack-plugin'); |
| const MiniCssExtractPlugin = require('mini-css-extract-plugin'); |
| const CssMinimizerPlugin = require("css-minimizer-webpack-plugin"); |
| const TerserJSPlugin = require('terser-webpack-plugin'); |
| const path = require('path'); |
| const process = require('process'); |
| |
| const srcPath = path.resolve(__dirname, 'src'); |
| const elmPath = path.join(srcPath, "elm"); |
| const dstPath = path.resolve(__dirname, 'dist'); |
| |
| const production = process.argv.mode === 'production'; |
| |
| const configVars = { |
| FIDLBOLT_BASE_URL: JSON.stringify(production ? 'go/fidlbolt' : null), |
| }; |
| |
| module.exports = (env, argv) => ({ |
| entry: './src/main.ts', |
| output: { |
| path: dstPath, |
| filename: 'bundle.js', |
| }, |
| resolve: { |
| extensions: ['.ts', '.js'] |
| }, |
| plugins: [ |
| new webpack.DefinePlugin(configVars), |
| new HtmlWebpackPlugin({ |
| template: 'src/index.html', |
| favicon: 'src/favicon.ico', |
| }), |
| new MiniCssExtractPlugin({ |
| filename: 'style.css', |
| }), |
| ], |
| optimization: { |
| minimizer: [ |
| new TerserJSPlugin({}), |
| new CssMinimizerPlugin({}), |
| ], |
| }, |
| module: { |
| rules: [ |
| { |
| test: /\.ts$/, |
| include: srcPath, |
| use: 'ts-loader', |
| }, |
| { |
| test: /\.elm$/, |
| include: elmPath, |
| use: { |
| loader: 'elm-webpack-loader', |
| options: { |
| cwd: elmPath, |
| debug: argv.mode == "development", |
| optimize: argv.mode == "production", |
| } |
| } |
| }, |
| { |
| test: /\.css$/, |
| use: [ |
| MiniCssExtractPlugin.loader, |
| 'css-loader', |
| ], |
| }, |
| ], |
| }, |
| }); |