tsconfig: cockpit plumbing
It was necessary to do a bit of plumbing to get typescript, webpack & vitest all happy. To do this we had had to create a separate tsconfig for the on-prem version and the service frontend. We override the module resolution for both config files. For on-prem we check modules in `pkg/lib` and for the service we resolve the modules to stub functions of the `cockpit` & `cockpit/fsinfo` modules. This was so typescript and webpack would not complain. For on-prem we had to intruct webpack to resolve modules from both `node_modules` and `pkg/lib`. While for the service we set the resulotion for the two modules to false, which means they won't get bundled with the service. Lastly, we needed to set some aliases in the vitest config so that vitest could resolve the `cockpit` & `cockpit/fsinfo` modules. Using the cjs `require` keyword to import cockpit would have worked to make typescript and webpack compile since these imports are not statically analysed like the `import` keyword is. However, this approach broke the tests as `require` imports are not supported in vitest.
This commit is contained in:
parent
4235885541
commit
2b82fa3c4b
6 changed files with 66 additions and 5 deletions
|
|
@ -2,7 +2,7 @@
|
|||
const path = require('path');
|
||||
|
||||
const CopyPlugin = require('copy-webpack-plugin');
|
||||
const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");
|
||||
const { sentryWebpackPlugin } = require('@sentry/webpack-plugin');
|
||||
const webpack = require('webpack');
|
||||
|
||||
const plugins = [];
|
||||
|
|
@ -105,6 +105,15 @@ module.exports = {
|
|||
useAgent: true,
|
||||
bounceProd: false,
|
||||
proxyVerbose: true,
|
||||
resolve: {
|
||||
alias: {
|
||||
// we don't wan't these packages bundled with
|
||||
// the service frontend, so we can set the aliases
|
||||
// to false
|
||||
cockpit: false,
|
||||
'cockpit/fsinfo': false,
|
||||
},
|
||||
},
|
||||
routes: {
|
||||
...(process.env.CONFIG_PORT && {
|
||||
[`${process.env.BETA ? '/beta' : ''}/config`]: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue