gaia-project/viewer/vue.config.js
coyotte508 bb39d47586 fix: RangeError on Rotate sectors + bundle load crash (viewer 5.13.1, engine 4.10.3)
- Replace all iterator spreads ([...map.values()] etc) with Array.from() across
  engine and viewer: under the TS->babel downlevel chain they compiled to
  __spreadArrays, which reads .length on an iterator and produced
  'RangeError: invalid array length' on 'Sector rotations finished' (the
  reported boardgamers.space crash), plus several latent same-class sites.
- Break the research-tracks.ts -> ../index barrel import cycle (imports
  Event/Expansion from leaf modules now): the cycle left Engine in TDZ and
  the whole bundle failed with 'Cannot access engine_Engine before
  initialization' at module eval under the rebuilt module order.
- Fix stale cache-loader output producing raw vue_1.default accesses for the
  vue webpack external (window.Vue has no .default): 'Cannot read properties
  of undefined (reading extend)' at load. Clean rebuild emits babel interop
  wrappers correctly. vue-global-shim.js added as belt-and-braces doc for the
  external's shape.
- Add autoprefixer as an explicit viewer devDependency (pnpm 11 no longer
  hoists it; the lib build failed on postCSS plugin load).
- Update stale spec type signatures surfaced by the import change (tile
  position as EventSource, loadFaction arity, ChargeRequest literal cast,
  AvailableCommand data narrowing, FederationInfo new fields).

Verified: engine 750 passing / 4 pending; viewer 809 passing; lint + prettier
clean; rebuilt UMD has zero iterator-spread call sites and loads + completes
sector rotation (with and without rotations) in Chromium against the real
bundle with CDN-provided Vue 2.
2026-09-01 08:09:31 +00:00

71 lines
3.2 KiB
JavaScript

/* eslint-disable */
const path = require("path");
const package = require("./package.json");
if (process.argv.includes("lib")) {
module.exports = {
lintOnSave: false,
outputDir: path.join(__dirname, "dist/package"),
// css: {extract: false}
chainWebpack: (config) => {
config.externals({
"bootstrap-vue": "BootstrapVue",
});
// 'vue' stays an external (the host page provides Vue), but TS's esModuleInterop emits
// `vue_1.default` and the host's `window.Vue` is a plain function with no `.default` -
// the raw external made the whole bundle throw "Cannot read properties of undefined
// (reading 'extend')" at module-eval. Resolving 'vue' through this shim normalizes the
// global into a proper ES-module shape so every import style works.
config.resolve.alias.set("vue$", path.join(__dirname, "vue-global-shim.js"));
// Inline ALL svg assets as data URIs instead of emitting img/*.svg files that resolve
// against the baked-in publicPath (the versioned jsDelivr URL). This makes the UMD lib a
// fully self-contained file, so it can be hosted anywhere (S3 upload via the BGS admin
// API, jsDelivr, ...) without 404ing its images. ~376 KiB of svg, well worth it.
// "url-loader" resolves through vue-cli's own resolveLoader search path.
const urlLoader = require.resolve("url-loader", {
paths: [path.dirname(require.resolve("@vue/cli-service/package.json"))],
});
config.module
.rule("svg")
.uses.clear()
.end()
.use("url-loader")
.loader(urlLoader)
.options({ limit: undefined, esModule: false });
// Package (transpile-only): the published bundle doesn't need full type-checking
// (that's covered by the test workflow). fork-ts-checker otherwise resolves a hoisted
// TS and fails on dependency .d.ts files (aria-query, csstype, @types/lodash) that
// newer pnpm no longer hoists, plus a chart.js typing change — none of which affect
// the emitted JS. This matches how the powergrid viewer packages its lib.
config.module
.rule("ts")
.use("ts-loader")
.tap((options) => ({ ...options, configFile: "tsconfig.build.json", transpileOnly: true }));
config.plugins.delete("fork-ts-checker");
},
publicPath: `//cdn.jsdelivr.net/npm/@gaia-project/viewer@${package.version}/dist/package/`,
};
} else {
module.exports = {
lintOnSave: false,
outputDir: path.join(__dirname, "dist/app"),
devServer: {
// For gitpod, it needs to be disabled
disableHostCheck: true,
},
chainWebpack: (config) => {
// The installed @types/jquery (3.5.x) emits hundreds of type errors under
// the pinned TypeScript 3.9, which makes the fork-ts-checker plugin hard-fail
// `vue-cli-service build` even though the app transpiles and runs fine.
// Transpile-only here so production builds succeed;
// real type-checking still happens via `tsc` / the engine test suite.
config.module
.rule("ts")
.use("ts-loader")
.tap((options) => ({ ...options, transpileOnly: true }));
if (config.plugins.has("fork-ts-checker")) {
config.plugins.delete("fork-ts-checker");
}
},
};
}