shrub/pkg/interface/config/webpack.prod.js

106 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-06-13 20:53:45 +03:00
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MomentLocalesPlugin = require("moment-locales-webpack-plugin");
const webpack = require("webpack");
const { execSync } = require("child_process");
2022-06-13 20:53:45 +03:00
const GIT_DESC = execSync("git describe --always", { encoding: "utf8" }).trim();
2020-04-30 01:48:25 +03:00
module.exports = {
2022-06-13 20:53:45 +03:00
mode: "production",
2020-04-30 01:48:25 +03:00
entry: {
2022-06-13 20:53:45 +03:00
app: "./src/index.tsx",
serviceworker: "./src/serviceworker.js",
2020-04-30 01:48:25 +03:00
},
module: {
rules: [
{
test: /\.(j|t)sx?$/,
2020-04-30 01:48:25 +03:00
use: {
2022-06-13 20:53:45 +03:00
loader: "babel-loader",
2020-04-30 01:48:25 +03:00
options: {
2022-06-13 20:53:45 +03:00
presets: [
"@babel/preset-env",
"@babel/typescript",
"@babel/preset-react",
],
2020-04-30 01:48:25 +03:00
plugins: [
2022-06-13 20:53:45 +03:00
"lodash",
"@babel/transform-runtime",
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-class-properties",
],
},
2020-04-30 01:48:25 +03:00
},
2022-06-13 20:53:45 +03:00
exclude:
/node_modules\/(?!(@tlon\/indigo-dark|@tlon\/indigo-light|@tlon\/indigo-react|@urbit\/api)\/).*/,
2020-04-30 01:48:25 +03:00
},
{
2022-06-13 20:53:45 +03:00
test: /\.css$/i,
2020-04-30 01:48:25 +03:00
use: [
// Creates `style` nodes from JS strings
2022-06-13 20:53:45 +03:00
"style-loader",
2020-04-30 01:48:25 +03:00
// Translates CSS into CommonJS
2022-06-13 20:53:45 +03:00
"css-loader",
2020-04-30 01:48:25 +03:00
// Compiles Sass to CSS
2022-06-13 20:53:45 +03:00
"sass-loader",
],
2021-09-28 07:14:33 +03:00
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
2022-06-13 20:53:45 +03:00
loader: "file-loader",
2021-09-28 07:14:33 +03:00
options: {
2022-06-13 20:53:45 +03:00
name: "[name].[ext]",
outputPath: "fonts/",
},
},
],
},
],
2020-04-30 01:48:25 +03:00
},
resolve: {
2022-06-13 20:53:45 +03:00
extensions: [".js", ".ts", ".tsx"],
2020-04-30 01:48:25 +03:00
},
2022-06-13 20:53:45 +03:00
devtool: "source-map",
2020-04-30 01:48:25 +03:00
// devServer: {
// contentBase: path.join(__dirname, './'),
// hot: true,
// port: 9000,
// historyApiFallback: true
// },
plugins: [
new MomentLocalesPlugin(),
new CleanWebpackPlugin(),
new webpack.DefinePlugin({
2022-06-13 20:53:45 +03:00
"process.env.LANDSCAPE_STREAM": JSON.stringify(
process.env.LANDSCAPE_STREAM
),
"process.env.LANDSCAPE_SHORTHASH": JSON.stringify(GIT_DESC),
"process.env.LANDSCAPE_STORAGE_VERSION": Date.now().toString(),
"process.env.LANDSCAPE_LAST_WIPE": "2021-10-20",
}),
2021-09-10 07:31:30 +03:00
new HtmlWebpackPlugin({
2022-06-13 20:53:45 +03:00
title: "Groups",
template: "./public/index.html",
favicon: "./src/assets/img/favicon.png",
}),
2020-04-30 01:48:25 +03:00
],
output: {
2021-01-28 08:30:48 +03:00
filename: (pathData) => {
2022-06-13 20:53:45 +03:00
return pathData.chunk.name === "app"
? "index.[contenthash].js"
: "[name].js";
2021-01-28 08:30:48 +03:00
},
2022-06-13 20:53:45 +03:00
path: path.resolve(__dirname, "../dist"),
publicPath: "/apps/landscape/",
2020-04-30 01:48:25 +03:00
},
optimization: {
minimize: true,
2022-06-13 20:53:45 +03:00
usedExports: true,
},
2020-04-30 01:48:25 +03:00
};