guesstimate/client/webpack.config.js

89 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-04-22 22:07:52 +02:00
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
const path = require('path');
const env = process.env;
2020-05-09 17:34:29 +02:00
const exec = require('child_process').execSync;
2020-04-22 22:07:52 +02:00
module.exports = {
mode: `${env.NODE_ENV ? env.NODE_ENV : 'production'}`,
entry: [
path.join(__dirname, './src/index.js')
],
2023-09-01 06:22:13 +02:00
devtool: env.NODE_ENV === 'production' ? 'source-map' : 'eval',
2020-04-22 22:07:52 +02:00
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].[hash].js',
publicPath: '/'
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"]
},
devServer: {
compress: true,
port: 8080,
historyApiFallback: true,
hot: env.NODE_ENV === 'development',
proxy: {
'/api': {
target: 'http://127.0.0.1:8081',
}
}
2020-04-22 22:07:52 +02:00
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loaders: ['ts-loader']
},
{
test: /\.module\.css$/,
use: [
{
loader: '@teamsupercell/typings-for-css-modules-loader',
},
{
loader: MiniCssExtractPlugin.loader,
},
{ loader: "css-loader", options: { modules: true } }
]
},
{
test: /^((?!\.module).)*css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{ loader: "css-loader" },
]
}
]
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
new HtmlWebpackPlugin({
2023-09-01 06:11:13 +02:00
title: '⏱️ Guesstimate',
2020-04-22 22:07:52 +02:00
scriptLoading: 'defer',
template: path.join(__dirname, 'src/index.html')
}),
new webpack.WatchIgnorePlugin([
/css\.d\.ts$/
]),
new MiniCssExtractPlugin({
filename: '[name].[hash].css'
}),
2020-05-09 17:34:29 +02:00
new webpack.DefinePlugin({
__BUILD__: JSON.stringify({
gitRef: getCurrentGitRef(),
buildDate: new Date(),
})
})
2020-04-22 22:07:52 +02:00
]
2020-05-09 17:34:29 +02:00
};
function getCurrentGitRef() {
return exec("git log -n 1 --pretty='format:%h'").toString()
}