forked from wavebeem/pkmn.help
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.gh-pages.js
85 lines (80 loc) · 2.28 KB
/
webpack.config.gh-pages.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
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-env node */
const path = require("path");
const glob = require("glob");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const PurgecssPlugin = require("purgecss-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const publicPath = "/pkmn.help/";
const development = {
stats: "minimal",
entry: [path.join(__dirname, "src/main.tsx")],
output: {
path: path.join(__dirname, "dist"),
publicPath,
filename: "[name].bundle.js",
chunkFilename: "[name].chunk.js",
},
devtool: "source-map",
devServer: {
contentBase: path.join(__dirname, "public"),
stats: "minimal",
historyApiFallback: true,
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
module: {
rules: [
{
test: /\.(ts|tsx|js)?$/,
loader: "ts-loader",
include: path.resolve(__dirname, "src"),
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
],
},
plugins: [
new CopyPlugin({ patterns: ["public"] }),
new MiniCssExtractPlugin({ filename: "[name].css" }),
new HtmlWebpackPlugin({
filename: path.join(__dirname, "dist/index.html"),
template: path.join(__dirname, "template/index.html"),
hash: true,
}),
new webpack.DefinePlugin({
"process.env.PUBLIC_PATH": JSON.stringify(publicPath),
}),
],
};
const production = {
...development,
plugins: [
...development.plugins,
new PurgecssPlugin({
paths: glob.sync(path.join(__dirname, "src/**/*.{ts,tsx,js}"), {
nodir: true,
}),
// e.g. `.type-grass` or `.type-fire`, these classes are constructed
// dynamically right now, so we have to safelist them so they won't get
// purged
safelist: [/^type-/],
}),
],
optimization: {
minimizer: [new CssMinimizerPlugin()],
},
};
if (process.env.ANALYZE) {
production.plugins.push(new BundleAnalyzerPlugin());
}
module.exports = (_, { mode }) => {
return { development, production }[mode];
};