@nx/vite
Version:
2 lines (1 loc) • 1.8 kB
TypeScript
export declare const viteConfigFixture = "/// <reference types=\"vitest\" />\nimport react from '@vitejs/plugin-react';\nimport dns from 'dns';\nimport { PluginOption, defineConfig } from 'vite';\nimport { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\n\ndns.setDefaultResultOrder('verbatim');\nconst BASE_HREF = '/app';\n\n/**\n * Adds <base href=\"/app\">` to the head of the index.html\n * The reason why the `base` configuration property doesn't work is because it makes\n * all assets served under `/app` of `/` and this impacts the download zip service worker\n * We only want to the service worker to listen to events related to downloads, but not capture any other events\n * and the only way to do this is make sure all assets are served from the root, but we still want our app path to be `/app`\n *\n * This mimics the same behavior we had with webpack before migrating to vite\n */\nconst baseHrefPlugin: () => PluginOption = () => {\n return {\n name: 'html-transform',\n transformIndexHtml(html) {\n return html.replace('<head>', `<head>\\n <base href=\"${BASE_HREF}\">`);\n },\n };\n};\n\nexport default defineConfig({\n cacheDir: '../../node_modules/.vite/jetstream',\n envPrefix: 'NX',\n\n server: {\n port: 4200,\n host: 'localhost',\n },\n\n build: {\n // Put all assets at the root of the app instead of under /assets\n assetsDir: './',\n sourcemap: true,\n rollupOptions: {\n output: {\n sourcemap: true,\n },\n },\n },\n\n plugins: [\n react({\n jsxImportSource: '@emotion/react',\n babel: {\n plugins: ['@emotion/babel-plugin'],\n },\n }),\n nxViteTsPaths(),\n baseHrefPlugin(),\n ],\n\n worker: {\n plugins: [\n nxViteTsPaths(),\n ],\n },\n});";