/// import analog from '@analogjs/platform'; import { resolve } from 'node:path'; import { defineConfig } from 'vite'; import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; // https://vitejs.dev/config/ export default defineConfig(() => { return { root: __dirname, cacheDir: `../node_modules/.vite`, build: { outDir: '../dist/./landing/client', reportCompressedSize: true, target: ['es2020'], }, server: { fs: { allow: ['.'], }, }, ssr: { // `@angular/cdk`, `@angular/material` and `@pi/ui` ship partially // compiled. Left external, Nitro loads them raw for SSR, the Angular // linker never runs over them and the first Material component to render // asks for the JIT compiler. Routing them through Vite's SSR transform // is where that linker lives. noExternal: [ '@angular/cdk', '@angular/material', '@ngx-translate/core', '@ngx-translate/http-loader', '@pi/ui', ], }, css: { preprocessorOptions: { scss: { // `@pi/ui` is imported by package path from `styles.scss`; sass only // resolves that with the workspace's node_modules on its load path. loadPaths: [resolve(__dirname, '../node_modules')], // The library's own sheets still use Dart Sass 1.x globals; their // warnings are not this app's to fix. quietDeps: true, }, }, }, plugins: [ analog({ // Nothing is prerendered on purpose. The page is assembled from // content the panel publishes, and it answers on `?lang=`, so a build // artefact would be both stale and wrong for two of three locales. // Freshness is bought back with cache headers below instead. prerender: { routes: [] }, nitro: { // Nitro leaves node_modules external in dev, so // `@analogjs/router/server` — which reads `import.meta.env` at module // scope — is imported raw by Node and throws before any page loader // runs. Inlining it puts the module back through the bundler, where // that expression is replaced. Production already inlines it. externals: { inline: ['@analogjs/router'] }, routeRules: { '/**': { headers: { 'cache-control': 'public, max-age=0, s-maxage=60, stale-while-revalidate=600', }, }, }, }, }), nxViteTsPaths(), ], test: { globals: true, environment: 'jsdom', setupFiles: ['src/test-setup.ts'], include: ['**/*.spec.ts'], reporters: ['default'], }, }; });