1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-09 16:21:51 +00:00
tobspr_shapez.io/gulp/webpack.config.js
EmeraldBlock 24ceb6664d ES modules and config refactor
- switches to ES modules in gulp and src
- uses dengr's webpack configs and package.json, with modifications
- removes gulp/package.json
- removes babel stuff
- removes gulp-load-plugins, instead importing gulp plugins manually
- removes unused and trivial packages
- upgrades packages
- uses path/posix, for gulp
- removes __dirname in favor of relative urls
2023-03-04 00:46:55 -06:00

100 lines
2.7 KiB
JavaScript

import CircularDependencyPlugin from "circular-dependency-plugin";
import { resolve } from "path/posix";
import webpack from "webpack";
import { getAllResourceImages, getRevision, getVersion } from "./buildutils.js";
const globalDefs = {
assert: "window.assert",
assertAlways: "window.assert",
abstract:
"window.assert(false, 'abstract method called of: ' + " +
"(this.name || (this.constructor && this.constructor.name)));",
G_IS_DEV: "true",
G_APP_ENVIRONMENT: JSON.stringify("development"),
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: "false",
G_IS_STANDALONE: "true",
G_IS_BROWSER: "false",
G_HAVE_ASSERT: "true",
};
/** @type {import("webpack").RuleSetRule[]} */
const moduleRules = [
{
test: /\.json$/,
enforce: "pre",
use: resolve("./loader.compressjson.cjs"),
type: "javascript/auto",
},
{
test: /\.js$/,
enforce: "pre",
exclude: /node_modules/,
use: [
{
loader: "webpack-strip-block",
options: {
start: "typehints:start",
end: "typehints:end",
},
},
],
},
{
test: /\.worker\.js$/,
use: [
{
loader: "worker-loader",
options: {
filename: "[fullhash].worker.js",
inline: "fallback",
},
},
],
},
{
test: /\.js$/,
resolve: {
fullySpecified: false,
},
},
];
/** @type {import("webpack").Configuration} */
export default {
mode: "development",
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"),
},
},
devtool: "cheap-source-map",
watch: true,
plugins: [
new webpack.DefinePlugin(globalDefs),
new webpack.IgnorePlugin({ resourceRegExp: /\.(png|jpe?g|svg)$/ }),
new webpack.IgnorePlugin({ resourceRegExp: /\.nobuild/ }),
new CircularDependencyPlugin({
exclude: /node_modules/,
failOnError: true,
allowAsyncCycles: false,
cwd: resolve("../src/js"),
}),
],
module: { rules: moduleRules },
experiments: {
topLevelAwait: true,
},
};