powergrid/viewer/vue.config.js

68 lines
3.5 KiB
JavaScript

// Small icons and sounds stay inline. Language chunks are uploaded with the entry and CSS.
const INLINE_ASSETS_LIMIT = 10 * 1024 * 1024;
const { dirname, join } = require('path');
const protocolDist = dirname(require.resolve('@boardgamers/protocol/viewer'));
module.exports = {
transpileDependencies: ['@boardgamers/protocol', 'zod'],
devServer: {
// For gitpod, it needs to be disabled
disableHostCheck: true,
// The dev server sends no cache directives of its own, only a weak ETag,
// so a browser is free to heuristically cache the bundle and never
// revalidate. On desktop this is hidden by DevTools' "disable cache";
// on a phone it shows up as "your fix didn't deploy" after every edit.
headers: {
'Cache-Control': 'no-store',
},
},
chainWebpack: (config) => {
// App and library builds use different Vue import transforms.
for (const name of ['js', 'ts', 'tsx', 'vue']) {
const rule = config.module.rule(name);
if (rule.uses.has('cache-loader')) {
rule.use('cache-loader').tap((options) => ({
...options,
cacheIdentifier: `${options.cacheIdentifier}:${process.env.VUE_CLI_BUILD_TARGET || 'app'}`,
}));
}
}
// Engine sources have their own tsconfig; every viewer worker must use
// the Vue config, including its legacy-decorator setting.
for (const name of ['ts', 'tsx']) {
config.module
.rule(name)
.use('ts-loader')
.tap((options) => ({
...options,
configFile: join(__dirname, 'tsconfig.json'),
...(process.env.NODE_ENV === 'test' ? { compilerOptions: { target: 'es2019' } } : {}),
}));
}
// Webpack 4 predates package exports; resolve the published ESM entry points.
config.resolve.alias.set('@boardgamers/protocol/viewer', join(protocolDist, 'viewer.js'));
config.resolve.alias.set('@boardgamers/protocol/chat/dom$', join(protocolDist, 'chat-dom.js'));
config.resolve.alias.set('@boardgamers/protocol/chat$', join(protocolDist, 'chat.js'));
config.resolve.alias.set('@boardgamers/protocol/tutorial/dom$', join(protocolDist, 'tutorial-dom.js'));
config.resolve.alias.set('@boardgamers/protocol/tutorial$', join(protocolDist, 'tutorial.js'));
// Use one ESM engine graph for both root and subpath imports.
config.resolve.alias.set('powergrid-engine$', join(__dirname, '../engine/index.ts'));
config.resolve.alias.set('lodash$', require.resolve('lodash'));
// vue-cli's svg rule uses plain file-loader (always emits files); replace it
// with url-loader so the icons are inlined. Reuse the url-loader already
// resolved for the images rule (it is not hoisted to our node_modules).
const urlLoader = config.module.rule('images').use('url-loader').get('loader');
config.module.rule('svg').uses.clear();
config.module.rule('svg').use('url-loader').loader(urlLoader).options({ limit: INLINE_ASSETS_LIMIT });
// Raise the inline threshold so audio (and any raster images) inline too
// instead of falling back to file-loader above 4 KiB.
for (const ruleName of ['images', 'media']) {
config.module
.rule(ruleName)
.use('url-loader')
.tap((options) => ({ ...options, limit: INLINE_ASSETS_LIMIT }));
}
},
};