1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-11 09:11:50 +00:00
tobspr_shapez.io/gulp/webpack.production.config.js
Даниїл Григор'єв c2855d528d
Slight improvements for the build process (#19)
* Unify the version source

Changes the development config to use version from package.json and
makes the production config use the same utility function. Also removes
the version file as it's no longer needed.

* Remove some Steam references from build process

Removes files needed to publish the game on Steam and related tasks that
can be only used by the developer anyway. Only the build process is
affected, the actual game part still supports Steam integration.

* Refactor/add packaging tasks

Adds new Gulp tasks to create a distributable package of the game. A
task for macOS is not provided because signing needs to be figured out
first. Package creation tasks are also aliased in package.json for
future usage in external tools or CI. Aside from that, alternative
methods of downloading the libGDX Texture Packer are dropped.
2024-04-14 19:03:27 +03:00

193 lines
5.8 KiB
JavaScript

import { resolve } from "path/posix";
import TerserPlugin from "terser-webpack-plugin";
import webpack from "webpack";
const { DefinePlugin, IgnorePlugin } = webpack;
import DeadCodePlugin from "webpack-deadcode-plugin";
import { getAllResourceImages, getRevision, getVersion } from "./buildutils.js";
const globalDefs = {
"assert": "false && window.assert",
"assertAlways": "window.assert",
"abstract": "window.assert(false, 'abstract method called');",
"globalConfig.debug": "({})",
"G_IS_DEV": "false",
"G_APP_ENVIRONMENT": JSON.stringify("release"),
"G_BUILD_TIME": new Date().getTime().toString(),
"G_BUILD_COMMIT_HASH": JSON.stringify(getRevision()),
"G_BUILD_VERSION": JSON.stringify(getVersion()),
"G_ALL_UI_IMAGES": JSON.stringify(getAllResourceImages()),
"G_IS_RELEASE": "true",
"G_IS_STANDALONE": "true",
"G_IS_BROWSER": "false",
"G_HAVE_ASSERT": "false",
};
/** @type {import("webpack").RuleSetRule[]} */
const moduleRules = [
{
test: /\.json$/,
enforce: "pre",
use: resolve("./loader.compressjson.cjs"),
type: "javascript/auto",
},
{
test: /\.jsx?$/,
enforce: "pre",
exclude: /node_modules/,
use: [
{
loader: "webpack-strip-block",
options: {
start: "typehints:start",
end: "typehints:end",
},
},
{
// TODO: Consider removing this separation
loader: "webpack-strip-block",
options: {
start: "dev:start",
end: "dev:end",
},
},
],
},
{
test: /\.[jt]sx?$/,
use: [
{
loader: "ts-loader",
options: {
configFile: resolve("../src/js/tsconfig.json"),
onlyCompileBundledFiles: true,
transpileOnly: true,
experimentalWatchApi: true,
},
},
],
resolve: {
fullySpecified: false,
},
},
{
test: /\.worker\.[jt]s$/,
use: [
{
loader: "worker-loader",
options: {
filename: "[fullhash].worker.js",
inline: "fallback",
},
},
],
},
];
/** @type {import("webpack").Configuration} */
export default {
mode: "production",
entry: resolve("../src/js/main.js"),
context: resolve(".."),
output: {
path: resolve("../build"),
filename: "bundle.js",
},
resolve: {
fallback: { fs: false },
alias: {
"global-compression": resolve("../src/js/core/lzstring.js"),
"root": resolve("../src/js/"),
},
fullySpecified: false,
extensions: [".ts", ".js", ".tsx", ".jsx"],
},
stats: { optimizationBailout: true },
devtool: false,
optimization: {
noEmitOnErrors: true,
removeAvailableModules: true,
removeEmptyChunks: true,
mergeDuplicateChunks: true,
flagIncludedChunks: true,
providedExports: true,
usedExports: true,
concatenateModules: true,
sideEffects: true,
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
ecma: 2020,
parse: {},
module: true,
toplevel: true,
keep_classnames: true,
keep_fnames: true,
compress: {
arguments: false,
drop_console: false,
global_defs: globalDefs,
keep_fargs: true,
keep_infinity: true,
passes: 2,
module: true,
pure_funcs: [
"Math.radians",
"Math.degrees",
"Math.round",
"Math.ceil",
"Math.floor",
"Math.sqrt",
"Math.hypot",
"Math.abs",
"Math.max",
"Math.min",
"Math.sin",
"Math.cos",
"Math.tan",
"Math.sign",
"Math.pow",
"Math.atan2",
],
toplevel: true,
unsafe_math: true,
unsafe_arrows: false,
},
mangle: {
eval: true,
keep_classnames: true,
keep_fnames: true,
module: true,
toplevel: true,
},
output: {
comments: false,
ascii_only: true,
beautify: false,
braces: false,
ecma: 2020,
},
},
}),
],
},
plugins: [
new DefinePlugin(globalDefs),
new IgnorePlugin({ resourceRegExp: /\.(png|jpe?g|svg)$/ }),
new IgnorePlugin({ resourceRegExp: /\.nobuild/ }),
new DeadCodePlugin({
patterns: ["../src/js/**/*.js"],
}),
],
module: { rules: moduleRules },
performance: {
maxEntrypointSize: 5120000,
maxAssetSize: 5120000,
},
experiments: {
topLevelAwait: true,
},
};