container/viewer/vue.config.js

65 lines
3.2 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 = {
productionSourceMap: false,
transpileDependencies: ['@boardgamers/protocol', 'zod'],
devServer: {
// For gitpod, it needs to be disabled
disableHostCheck: true,
},
chainWebpack: (config) => {
if (config.plugins.has('fork-ts-checker')) {
config.plugin('fork-ts-checker').tap((args) => {
args[0].vue.compiler = 'vue-template-compiler';
return args;
});
}
// 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'),
}));
}
// Webpack 4 predates package exports; resolve the published ESM entry points.
config.resolve.alias.set('@boardgamers/protocol/player-symbols$', join(protocolDist, 'player-symbols.js'));
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'));
// 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 }));
}
},
};