Skip to content

Commit

Permalink
chore(misc): add tsconfig/jsconfig path alias support
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Feb 19, 2025
1 parent bd69e35 commit 33b5c7d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions e2e/nx-init/src/nx-init-react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ describe('nx init (for React - legacy)', () => {
expect(packageJson.dependencies['redux']).toBeDefined();
expect(packageJson.name).toEqual(appName);

const viteConfig = readFile(`vite.config.js`);
expect(viteConfig).toContain('port: 4200'); // default port
const viteConfig = readFile(`vite.config.mjs`);
expect(viteConfig).toContain('port: 3000'); // default port

runCLI(`build ${appName}`);
checkFilesExist(`dist/${appName}/index.html`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function installDependencies(options: NormalizedOptions) {
'web-vitals',
'jest-watch-typeahead',
'vite',
'vite-tsconfig-paths',
'vitest',
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function writeViteConfig(
isStandalone: boolean,
isJs: boolean
) {
let port = 4200;
let port = 3000;

// Use PORT from .env file if it exists in project.
if (existsSync(`../.env`)) {
Expand All @@ -18,10 +18,11 @@ export function writeViteConfig(
}

writeFileSync(
isStandalone ? 'vite.config.js' : `apps/${appName}/vite.config.js`,
isStandalone ? 'vite.config.mjs' : `apps/${appName}/vite.config.mjs`,
`import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { default as replace } from '@rollup/plugin-replace';
import replace from '@rollup/plugin-replace';
import tsconfigPaths from 'vite-tsconfig-paths';
// Match CRA's environment variables.
// TODO: Replace these with VITE_ prefixed environment variables, and using import.meta.env.VITE_* instead of process.env.REACT_APP_*.
Expand Down Expand Up @@ -50,7 +51,11 @@ export default defineConfig({
setupFiles: 'src/setupTests.${isJs ? 'js' : 'ts'}',
css: true,
},
plugins: [react(), replace({ values: craEnvVars, preventAssignment: true })],
plugins: [
react(),
replace({ values: craEnvVars, preventAssignment: true }),
tsconfigPaths(),
],
});
`
);
Expand Down

0 comments on commit 33b5c7d

Please sign in to comment.