1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00
tobspr_shapez.io/gulp/webpack.production.config.js
DJ1TJOO 9cb3e0c398 Squashed commit of the following:
commit ea2f32b3ff
Author: tobspr <tobias.springer1@googlemail.com>
Date:   Tue Feb 15 09:09:30 2022 +0100

    Fix examples

commit 561318b7db
Author: Dimava <dimava2@ya.ru>
Date:   Tue Feb 15 10:31:47 2022 +0300

    mark all abstract functions abstract (#1383)

commit 81d65e5801
Author: WaffleDevsAlt <81845843+WaffleDevsAlt@users.noreply.github.com>
Date:   Tue Feb 15 02:31:02 2022 -0500

    Removes unwanted ], (#1384)

    The ], breaks build, with a core error

commit 4f0af32a5e
Author: Ved_s <53968411+Ved-s@users.noreply.github.com>
Date:   Mon Feb 14 07:14:34 2022 +1100

    Update base-ru.yaml (#1312)

    * Update base-ru.yaml

    I think other's comments about the game should stay in English, as Russian translation cannot precisely describe this

    * Update base-ru.yaml

commit 3f3a2e0981
Author: Daan Breur <git@daanbreur.systems>
Date:   Sun Feb 13 21:11:52 2022 +0100

    NL Translations for Mods and puzzleDLC (#1381)

    * [NL] Mods and puzzleDLC

    * Update base-nl.yaml

    * Update base-nl.yaml

commit c4f26320a4
Author: dobidon <35607008+dobidon@users.noreply.github.com>
Date:   Sun Feb 13 23:11:38 2022 +0300

    Translating new keys (#1380)

commit cb5c3f798a
Author: Pimak <37274338+Pimak@users.noreply.github.com>
Date:   Sun Feb 13 21:11:16 2022 +0100

    Update base-fr.yaml for mods translation (#1377)

commit dee4f23b7e
Author: Sense101 <67970865+Sense101@users.noreply.github.com>
Date:   Sun Feb 13 20:11:02 2022 +0000

    Fix method for adding variants to an existing building (#1378)

commit b7bc2ac1b7
Author: jbelbaz <32191774+jbelbaz@users.noreply.github.com>
Date:   Sun Feb 13 21:10:11 2022 +0100

    Update base-fr.yaml (#1328)

    Change of a few lines in English. I was unable to verify in-game integration ... I hope my work will fit.
    glad to help :D

commit 93b9340ab7
Author: Pimak <37274338+Pimak@users.noreply.github.com>
Date:   Sun Feb 13 21:09:56 2022 +0100

    Update README.md (#1376)

    Small mistake

commit f534a88f80
Author: Bagel03 <70449196+Bagel03@users.noreply.github.com>
Date:   Sun Feb 13 15:09:41 2022 -0500

    Fix that whole export debacle (#1370)

    * Re-add setting exports

    * Update webpack.production.config.js

    * Update mod.js

    * Slight change

    * Update mod.js

    * Update webpack.production.config.js

    * Update webpack.config.js

commit dab4aa9cda
Author: Emerald Block <69981203+EmeraldBlock@users.noreply.github.com>
Date:   Sun Feb 13 14:07:02 2022 -0600

    fix fs-job sanitization (#1375)

commit 4466821557
Author: Thomas (DJ1TJOO) <44841260+DJ1TJOO@users.noreply.github.com>
Date:   Sun Feb 13 21:06:42 2022 +0100

    Added display hook for getting the signelton and the drawing (#1374)

commit 65ae26cb53
Author: Thomas (DJ1TJOO) <44841260+DJ1TJOO@users.noreply.github.com>
Date:   Sun Feb 13 21:06:24 2022 +0100

    Added hook for storage can accept item (#1373)

    * Added hook for storage can accept item

    * Fixed order

commit e5742fd577
Author: Thomas (DJ1TJOO) <44841260+DJ1TJOO@users.noreply.github.com>
Date:   Sun Feb 13 21:06:10 2022 +0100

    Added constant signal resolver hook (#1372)

    * Added constant signal resolver hook

    * Added apply

commit 41c6b1c595
Author: Thomas (DJ1TJOO) <44841260+DJ1TJOO@users.noreply.github.com>
Date:   Sun Feb 13 21:05:58 2022 +0100

    Added mod processing requirements (#1371)

    * Added mod processing requirements

    * Added missing bind

    * Renamed to mods
2022-02-15 12:02:00 +01:00

272 lines
10 KiB
JavaScript

// @ts-nocheck
const path = require("path");
const webpack = require("webpack");
const { getRevision, getVersion, getAllResourceImages } = require("./buildutils");
const lzString = require("lz-string");
const TerserPlugin = require("terser-webpack-plugin");
const StringReplacePlugin = require("string-replace-webpack-plugin");
const UnusedFilesPlugin = require("unused-files-webpack-plugin").UnusedFilesWebpackPlugin;
module.exports = ({
enableAssert = false,
environment,
es6 = false,
standalone = false,
isBrowser = true,
mobileApp = false,
chineseVersion = false,
wegameVersion = false,
}) => {
const globalDefs = {
assert: enableAssert ? "window.assert" : "false && window.assert",
assertAlways: "window.assert",
abstract: "window.assert(false, 'abstract method called');",
G_IS_DEV: "false",
G_CHINA_VERSION: JSON.stringify(chineseVersion),
G_WEGAME_VERSION: JSON.stringify(wegameVersion),
G_IS_RELEASE: environment === "prod" ? "true" : "false",
G_IS_STANDALONE: standalone ? "true" : "false",
G_IS_BROWSER: isBrowser ? "true" : "false",
G_IS_MOBILE_APP: mobileApp ? "true" : "false",
G_TRACKING_ENDPOINT: JSON.stringify(
lzString.compressToEncodedURIComponent("https://tracking.shapez.io/v1")
),
G_APP_ENVIRONMENT: JSON.stringify(environment),
G_HAVE_ASSERT: enableAssert ? "true" : "false",
G_BUILD_TIME: "" + new Date().getTime(),
G_BUILD_COMMIT_HASH: JSON.stringify(getRevision()),
G_BUILD_VERSION: JSON.stringify(getVersion()),
G_ALL_UI_IMAGES: JSON.stringify(getAllResourceImages()),
};
const minifyNames = false;
return {
mode: "production",
entry: {
"bundle.js": [path.resolve(__dirname, "..", "src", "js", "main.js")],
},
node: {
fs: "empty",
},
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "..", "build"),
},
context: path.resolve(__dirname, ".."),
stats: {
// Examine all modules
maxModules: Infinity,
// Display bailout reasons
optimizationBailout: true,
},
// devtool: "source-map",
devtool: false,
resolve: {
alias: {
"global-compression": path.resolve(__dirname, "..", "src", "js", "core", "lzstring.js"),
},
},
optimization: {
minimize: true,
// namedModules: true,
noEmitOnErrors: true,
removeAvailableModules: true,
removeEmptyChunks: true,
mergeDuplicateChunks: true,
flagIncludedChunks: true,
occurrenceOrder: true,
providedExports: true,
usedExports: true,
concatenateModules: true,
sideEffects: true,
minimizer: [
new TerserPlugin({
parallel: true,
sourceMap: false,
cache: false,
terserOptions: {
ecma: es6 ? 6 : 5,
parse: {},
module: true,
toplevel: true,
keep_classnames: !minifyNames,
keep_fnames: !minifyNames,
keep_fargs: !minifyNames,
safari10: true,
compress: {
arguments: false, // breaks
drop_console: false,
global_defs: globalDefs,
keep_fargs: !minifyNames,
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,
warnings: true,
},
mangle: {
reserved: ["__$S__"],
eval: true,
keep_classnames: !minifyNames,
keep_fnames: !minifyNames,
module: true,
toplevel: true,
safari10: true,
},
output: {
comments: false,
ascii_only: true,
beautify: false,
braces: false,
ecma: es6 ? 6 : 5,
preamble:
"/* shapez.io Codebase - Copyright 2022 tobspr Games - " +
getVersion() +
" @ " +
getRevision() +
" */",
},
},
}),
],
},
performance: {
maxEntrypointSize: 5120000,
maxAssetSize: 5120000,
},
plugins: [
new webpack.DefinePlugin(globalDefs),
new UnusedFilesPlugin({
failOnUnused: false,
cwd: path.join(__dirname, "..", "src", "js"),
patterns: ["../src/js/**/*.js"],
}),
],
module: {
rules: [
{
test: /\.json$/,
enforce: "pre",
use: ["./gulp/loader.compressjson"],
type: "javascript/auto",
},
{ test: /\.(png|jpe?g|svg)$/, loader: "ignore-loader" },
{ test: /\.nobuild/, loader: "ignore-loader" },
{
test: /\.js$/,
enforce: "pre",
exclude: /node_modules/,
use: [
{
loader: "webpack-strip-block",
options: {
start: "typehints:start",
end: "typehints:end",
},
},
{
loader: "webpack-strip-block",
options: {
start: "dev:start",
end: "dev:end",
},
},
{
loader: "webpack-strip-block",
options: {
start: "wires:start",
end: "wires:end",
},
},
],
},
{
test: /\.js$/,
use: [
// "thread-loader",
{
loader: path.resolve(__dirname, "mod.js"),
},
{
loader: "babel-loader?cacheDirectory",
options: {
configFile: require.resolve(
es6 ? "./babel-es6.config.js" : "./babel.config.js"
),
},
},
"uglify-template-string-loader", // Finally found this plugin
StringReplacePlugin.replace({
replacements: [
{ pattern: /globalConfig\.tileSize/g, replacement: () => "32" },
{ pattern: /globalConfig\.halfTileSize/g, replacement: () => "16" },
{
pattern: /globalConfig\.beltSpeedItemsPerSecond/g,
replacement: () => "2.0",
},
{ pattern: /globalConfig\.debug/g, replacement: () => "''" },
],
}),
],
},
{
test: /\.worker\.js$/,
use: [
{
loader: "worker-loader",
options: {
fallback: false,
inline: true,
},
},
{
loader: "babel-loader?cacheDirectory",
options: {
configFile: require.resolve(
es6 ? "./babel-es6.config.js" : "./babel.config.js"
),
},
},
],
},
{
test: /\.md$/,
use: ["html-loader", "markdown-loader"],
},
{
test: /\.ya?ml$/,
type: "json", // Required by Webpack v4
use: "yaml-loader",
},
],
},
};
};