-
Notifications
You must be signed in to change notification settings - Fork 21
/
webpack.config.js
119 lines (114 loc) · 3.1 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright (c) 2020, conda-store development team
*
* This file is distributed under the terms of the BSD 3 Clause license.
* The full license can be found in the LICENSE file.
*/
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const Dotenv = require("dotenv-webpack");
const webpack = require("webpack");
const packageJson = require('./package.json');
const isProd = process.env.NODE_ENV === "production";
const ASSET_PATH = isProd ? "" : "/";
const version = packageJson.version;
// Calculate hash based on content, will be used when generating production
// bundles
const cssLoader = {
loader: "css-loader",
options: {
modules: {
auto: true,
localIdentName: isProd ? "[hash:base64]" : "[name]__[local]--[hash:base64:5]",
},
},
};
const rules = [
{
test: /\.js$/,
use: "source-map-loader",
enforce: "pre",
exclude: /node_modules/,
},
{
test: /\.(css|less)$/,
use: [
isProd ? MiniCssExtractPlugin.loader : "style-loader",
cssLoader,
"less-loader",
],
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
type: "asset",
parser: {
dataUrlCondition: {
maxSize: 10 * 1024, // 10kb
},
},
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
},
],
},
];
module.exports = {
mode: isProd ? "production" : "development",
// generate a sourcemap for production, in dev we generate mapping faster
devtool: isProd ? "source-map" : "eval-cheap-module-source-map",
devServer: {
port: 8000,
// enable hot module replacement
hot: true,
},
entry: ["src/index.tsx", "src/main.tsx"],
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js",
publicPath: ASSET_PATH,
clean: true,
},
module: { rules },
resolve: {
modules: ["node_modules", path.resolve(__dirname)],
extensions: [".tsx", ".ts", ".jsx", ".js", ".less", ".css"],
},
plugins: [
new HtmlWebpackPlugin({ title: "conda-store" }),
new HtmlWebpackPlugin({
filename: "memory-router-test.html",
template: "test/playwright/memory-router-test.html",
}),
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new Dotenv(),
new webpack.EnvironmentPlugin(["REACT_APP_VERSION"]),
new webpack.ids.HashedModuleIdsPlugin(),
new webpack.DefinePlugin({
'process.env.VERSION': JSON.stringify(version),
}),
// Add comment to generated files indicating the hash and ui version
// this is helpful for vendoring with server
new webpack.BannerPlugin({
banner: `file: [file], fullhash:[fullhash] - ui version: ${version}`,
include: [/\.css$/, /\.html$/],
}),
],
optimization: {
minimize: isProd,
minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
},
};