Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bundling): vite plugin executors (#13032)
- Loading branch information
Showing
23 changed files
with
1,534 additions
and
13 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,15 +1,135 @@ | ||
import { cleanupProject, newProject } from '@nrwl/e2e/utils'; | ||
import { | ||
cleanupProject, | ||
createFile, | ||
killPorts, | ||
newProject, | ||
readFile, | ||
rmDist, | ||
runCLI, | ||
runCommandUntil, | ||
uniq, | ||
updateFile, | ||
updateProjectConfig, | ||
} from '@nrwl/e2e/utils'; | ||
|
||
const myApp = uniq('my-app'); | ||
|
||
describe('Vite Plugin', () => { | ||
let proj: string; | ||
|
||
beforeEach(() => (proj = newProject())); | ||
beforeEach(() => { | ||
proj = newProject(); | ||
runCLI(`generate @nrwl/react:app ${myApp}`); | ||
runCLI(`generate @nrwl/vite:init`); | ||
updateFile( | ||
`apps/${myApp}/index.html`, | ||
` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>My App</title> | ||
<base href="/" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link rel="icon" type="image/x-icon" href="favicon.ico" /> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="src/main.tsx"></script> | ||
</body> | ||
</html> | ||
` | ||
); | ||
|
||
createFile( | ||
`apps/${myApp}/vite.config.ts`, | ||
` | ||
import { defineConfig } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
import plugin from 'vite-tsconfig-paths'; | ||
export default defineConfig({ | ||
plugins: [ | ||
react(), | ||
plugin({ | ||
root: '../../', | ||
projects: ['tsconfig.base.json'], | ||
}), | ||
], | ||
});` | ||
); | ||
|
||
updateFile( | ||
`apps/${myApp}/tsconfig.json`, | ||
` | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"jsx": "react-jsx", | ||
"allowJs": false, | ||
"esModuleInterop": false, | ||
"allowSyntheticDefaultImports": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"isolatedModules": true, | ||
"lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"noEmit": true, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"target": "ESNext", | ||
"types": ["vite/client"], | ||
"useDefineForClassFields": true | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.app.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} | ||
` | ||
); | ||
|
||
updateProjectConfig(myApp, (config) => { | ||
config.targets.build.executor = '@nrwl/vite:build'; | ||
config.targets.serve.executor = '@nrwl/vite:dev-server'; | ||
|
||
config.targets.build.options = { | ||
outputPath: `dist/apps/${myApp}`, | ||
}; | ||
|
||
config.targets.serve.options = { | ||
buildTarget: `${myApp}:build`, | ||
}; | ||
|
||
return config; | ||
}); | ||
}); | ||
afterEach(() => cleanupProject()); | ||
|
||
xit('should build applications', () => {}); | ||
it('should build applications', async () => { | ||
runCLI(`build ${myApp}`); | ||
expect(readFile(`dist/apps/${myApp}/index.html`)).toBeDefined(); | ||
rmDist(); | ||
}, 200000); | ||
|
||
describe('serve using Vite', () => { | ||
afterEach(() => killPorts()); | ||
|
||
xit('should serve applications in dev mode', () => {}); | ||
it('should serve applications in dev mode', async () => { | ||
const p = await runCommandUntil(`run ${myApp}:serve`, (output) => { | ||
return output.includes('Local:'); | ||
}); | ||
p.kill(); | ||
}, 200000); | ||
}); | ||
|
||
xit('should test applications', () => {}); | ||
}); |
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
Oops, something went wrong.
8d103f3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev