-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…3364) <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior <!-- This is the behavior we have today --> The migration to update vite config is incorrectly matching other object literal and arrow functions ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Ensure more accurate updating of vite config file ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #20921
- Loading branch information
Showing
4 changed files
with
153 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/vite/src/migrations/update-17-2-0/lib/vite-config-with-additional-js.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
export const viteConfigFixture = `/// <reference types="vitest" /> | ||
import react from '@vitejs/plugin-react'; | ||
import dns from 'dns'; | ||
import { PluginOption, defineConfig } from 'vite'; | ||
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; | ||
dns.setDefaultResultOrder('verbatim'); | ||
const BASE_HREF = '/app'; | ||
/** | ||
* Adds <base href="/app">\` to the head of the index.html | ||
* The reason why the \`base\` configuration property doesn't work is because it makes | ||
* all assets served under \`/app\` of \`/\` and this impacts the download zip service worker | ||
* We only want to the service worker to listen to events related to downloads, but not capture any other events | ||
* 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\` | ||
* | ||
* This mimics the same behavior we had with webpack before migrating to vite | ||
*/ | ||
const baseHrefPlugin: () => PluginOption = () => { | ||
return { | ||
name: 'html-transform', | ||
transformIndexHtml(html) { | ||
return html.replace('<head>', \`<head>\\n <base href="\${BASE_HREF}">\`); | ||
}, | ||
}; | ||
}; | ||
export default defineConfig({ | ||
cacheDir: '../../node_modules/.vite/jetstream', | ||
envPrefix: 'NX', | ||
server: { | ||
port: 4200, | ||
host: 'localhost', | ||
}, | ||
build: { | ||
// Put all assets at the root of the app instead of under /assets | ||
assetsDir: './', | ||
sourcemap: true, | ||
rollupOptions: { | ||
output: { | ||
sourcemap: true, | ||
}, | ||
}, | ||
}, | ||
plugins: [ | ||
react({ | ||
jsxImportSource: '@emotion/react', | ||
babel: { | ||
plugins: ['@emotion/babel-plugin'], | ||
}, | ||
}), | ||
nxViteTsPaths(), | ||
baseHrefPlugin(), | ||
], | ||
worker: { | ||
plugins: [ | ||
nxViteTsPaths(), | ||
], | ||
}, | ||
});`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters