forked from SHSGames/shsgames.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.conf.ts
133 lines (130 loc) · 3.15 KB
/
webpack.conf.ts
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* eslint @typescript-eslint/no-var-requires: off */
import path from "path";
import { Configuration, DefinePlugin } from "webpack";
import OfflinePlugin from "offline-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import WebpackPwaManifest, { ManifestOptions } from "webpack-pwa-manifest";
import CopyWebpackPlugin from "copy-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import manifest from "./web/manifest";
import fs from "fs";
import YAML from "yaml";
export = <Configuration>{
entry: [ "./web/__compile_cache/ts/index.js" ],
output: {
path: path.resolve("public_html/"),
filename: "app/[name].[contenthash].js"
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: "babel-loader",
options: {
compact: true,
presets: [ "@babel/preset-react", "@babel/preset-env" ],
plugins: [ "@babel/plugin-proposal-class-properties" ]
}
}
}, {
test: /\.(c|le)ss/i,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: "../"
}
},
{
loader: "css-loader"
},
{
loader: "less-loader",
options: {
lessOptions: {
rewriteUrls: "local"
}
}
}
]
}, {
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: "file-loader",
options: {
name: "static/[contenthash].[ext]"
}
}
]
}, {
include: path.resolve("web/static"),
use: [
{
loader: "file-loader",
options: {
name: "static/[contenthash].[ext]"
}
}
]
}, {
test: /\.(txt|md|pem|raw)$/,
use: [
{
loader: "raw-loader"
}
]
} ]
},
plugins: [
new CleanWebpackPlugin,
new HtmlWebpackPlugin({
template: "web/index.html",
favicon: "web/static/icon.png",
base: "/",
templateParameters: {
title: manifest.name,
description: manifest.description
}
}),
new MiniCssExtractPlugin({
filename: "app/[name].[contenthash].css"
}),
new WebpackPwaManifest(<ManifestOptions>{
filename: "manifest.json",
...manifest
}),
new CopyWebpackPlugin({
patterns: [
{ from: "web/ads.txt", to: "." },
{ from: "web/robots.txt", to: "." },
{ from: "web/IodineGBA.html", to: "." },
{ from: "web/built-games", to: "built-games" },
{ from: "web/ruffle", to: "ruffle" }
]
}),
new DefinePlugin({
APP_MANIFEST: JSON.stringify(manifest),
APP_CONFIG: JSON.stringify(YAML.parse(fs.existsSync(path.resolve("config.yml")) ? fs.readFileSync(path.resolve("config.yml"), "utf8") : ""))
}),
new OfflinePlugin
],
resolve: {
extensions: [ ".js" ],
roots: [
path.resolve("./"),
path.resolve("./node_modules"),
path.resolve("./web/__compile_cache/ts")
],
alias: {
"static": path.resolve("./web/static"),
"views": path.resolve("./web/__compile_cache/ts/views"),
"runtime": path.resolve("./web/__compile_cache/ts/runtime"),
"src": path.resolve("./web/__compile_cache/ts/src"),
"styles": path.resolve("./web/styles"),
"components": path.resolve("./web/__compile_cache/ts/components")
}
}
};