guesstimate/client/webpack.config.js

97 lines
2.2 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')
],
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({
title: 'Guesstimate',
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({
version: getCurrentVersion(),
gitRef: getCurrentGitRef(),
buildDate: new Date(),
})
})
2020-04-22 22:07:52 +02:00
]
2020-05-09 17:34:29 +02:00
};
function getCurrentVersion() {
let version
try {
version = exec("git describe --abbrev=0 2>/dev/null")
} catch(err) {}
return version ? version : "0.0.0";
}
function getCurrentGitRef() {
return exec("git log -n 1 --pretty='format:%h'").toString()
}