mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-13 02:01:51 +00:00
TypeScript compiler on its own will only inject this import, but not resolve it. The bundler is supposed to resolve the import, so just do that.
114 lines
3.2 KiB
JavaScript
114 lines
3.2 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_HAVE_ASSERT: "true",
|
|
};
|
|
|
|
/** @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",
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
test: /\.[jt]sx?$/,
|
|
use: [
|
|
{
|
|
loader: "ts-loader",
|
|
|
|
options: {
|
|
configFile: resolve("../src/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: "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"),
|
|
"root": resolve("../src/js/"),
|
|
"@/jsx-runtime": resolve("../src/js/jsx-runtime.ts"),
|
|
},
|
|
fullySpecified: false,
|
|
extensions: [".ts", ".js", ".tsx", ".jsx"],
|
|
},
|
|
devtool: "cheap-source-map",
|
|
cache: false,
|
|
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,
|
|
},
|
|
};
|