-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
98 lines (97 loc) · 4.97 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
const HtmlWebpackPlugin = require("html-webpack-plugin")
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin")
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const TerserJSPlugin = require("terser-webpack-plugin")
const WebpackObfuscator = require("webpack-obfuscator")
const CopyPlugin = require("copy-webpack-plugin")
const MinimizerCSSPlugin = require("css-minimizer-webpack-plugin")
const nodeExternals = require("webpack-node-externals")
const webpack = require("webpack")
const path = require("path")
const Dotenv = require("dotenv-webpack")
let exclude = [/node_modules/, /dist/]
let webExclude = [...exclude, /server.tsx/, /routes/]
let nodeExclude = [...exclude, /structures\/BrowserFunctions.tsx/]
module.exports = [
{
target: "web",
entry: "./index",
mode: "production",
node: {__dirname: false},
output: {publicPath: "/", globalObject: "this", filename: "script.js", chunkFilename: "[id].js", path: path.resolve(__dirname, "./dist")},
resolve: {extensions: [".js", ".jsx", ".ts", ".tsx"], alias: {"react-dom$": "react-dom/profiling", "scheduler/tracing": "scheduler/tracing-profiling"},
fallback: {fs: false, "process/browser": require.resolve("process/browser"), path: require.resolve("path-browserify"),
crypto: require.resolve("crypto-browserify"), stream: require.resolve("stream-browserify"), assert: require.resolve("assert/"),
zlib: require.resolve("browserify-zlib"), url: require.resolve("url/"), os: require.resolve("os/")}},
performance: {hints: false},
optimization: {minimize: false, minimizer: [new TerserJSPlugin({extractComments: false}), new WebpackObfuscator(), new MinimizerCSSPlugin()], moduleIds: "named",
splitChunks: {chunks(chunk) {return false}}},
module: {
rules: [
{test: /\.(jpe?g|png|gif|webp|svg|mp3|wav|mp4|webm|glb|obj|fbx|ttf|otf)$/, exclude: webExclude, use: [{loader: "file-loader", options: {name: "[path][name].[ext]"}}]},
{test: /\.(txt|sql)$/, exclude: webExclude, use: ["raw-loader"]},
{test: /\.html$/, exclude: webExclude, use: [{loader: "html-loader", options: {sources: false, minimize: false}}]},
{test: /\.css$/, exclude: webExclude, use: [{loader: MiniCssExtractPlugin.loader}, "css-loader"]},
{test: /\.less$/, exclude: webExclude, use: [{loader: MiniCssExtractPlugin.loader}, "css-loader", {loader: "less-loader"}]},
{test: /\.(tsx?|jsx?)$/, exclude: webExclude, use: [{loader: "ts-loader", options: {transpileOnly: true}}]}
]
},
plugins: [
new Dotenv(),
new ForkTsCheckerWebpackPlugin({typescript: {memoryLimit: 8192}}),
new webpack.HotModuleReplacementPlugin(),
new MiniCssExtractPlugin({
filename: "styles.css",
chunkFilename: "[id].css"
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "./index.html"),
minify: false
}),
new webpack.ProvidePlugin({
process: "process/browser",
Buffer: ["buffer", "Buffer"],
}),
new CopyPlugin({
patterns: [
{from: "structures/bitcrusher.js", to: "[name][ext]"},
{from: "structures/soundtouch.js", to: "[name][ext]"},
{from: "structures/webpxmux.wasm", to: "[name][ext]"},
{from: "structures/avif_enc.wasm", to: "[name][ext]"},
{from: "structures/jxl_enc.wasm", to: "[name][ext]"}
]
})
]
},
{
target: "node",
entry: "./server",
mode: "production",
node: {__dirname: false},
externals: [nodeExternals()],
output: {filename: "server.js", chunkFilename: "[id].js", path: path.resolve(__dirname, "./dist")},
resolve: {extensions: [".js", ".jsx", ".ts", ".tsx"],
fallback: {zlib: require.resolve("browserify-zlib")}},
performance: {hints: false},
optimization: {minimize: false, minimizer: [new TerserJSPlugin({extractComments: false}), new WebpackObfuscator()], moduleIds: "named"},
module: {
rules: [
{test: /\.(jpe?g|png|webp|gif|svg|mp3|wav|mp4|webm|glb|obj|fbx|ttf|otf)$/, exclude: nodeExclude, use: [{loader: "file-loader", options: {name: "[path][name].[ext]"}}]},
{test: /\.(txt|sql)$/, exclude: nodeExclude, use: ["raw-loader"]},
{test: /\.html$/, exclude: nodeExclude, use: [{loader: "html-loader", options: {minimize: false}}]},
{test: /\.css$/, exclude: nodeExclude, use: [{loader: MiniCssExtractPlugin.loader}, "css-loader"]},
{test: /\.less$/, exclude: nodeExclude, use: [{loader: MiniCssExtractPlugin.loader}, "css-loader", {loader: "less-loader"}]},
{test: /\.(tsx?|jsx?)$/, exclude: nodeExclude, use: [{loader: "ts-loader", options: {transpileOnly: true}}]}
]
},
plugins: [
new Dotenv(),
new ForkTsCheckerWebpackPlugin(),
new webpack.HotModuleReplacementPlugin(),
new MiniCssExtractPlugin({
filename: "styles.css",
chunkFilename: "[id].css"
})
]
}
]