feat(bundling): add initial vite plugin (#12969)

This commit is contained in:
Jack Hsu 2022-11-03 13:19:29 -04:00 committed by GitHub
parent 80813c238b
commit 8edcdac5eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 439 additions and 1 deletions

View File

@ -0,0 +1,19 @@
{
"githubRoot": "https://github.com/nrwl/nx/blob/master",
"name": "vite",
"packageName": "@nrwl/vite",
"description": "The Nx Plugin for building and testing applications using Vite (Early Release)",
"root": "/packages/vite",
"source": "/packages/vite/src",
"documentation": [
{
"name": "Overview",
"id": "overview",
"path": "/packages/vite",
"file": "shared/vite-plugin",
"content": "The Nx plugin for [Vite](https://vitejs.dev/) and [Vitest](https://vitest.dev/).\n\n{% callout type=\"warning\" title=\"Early release plugin\" %}\nThis Nx plugin is in active development and may not be ready for real-world use. The planned release date for the stable plugin is December, 2022.\n{% /callout %}\n\nWhy should you use this plugin?\n\n- Instant dev server start\n- Lightning fast Hot-Module Reloading\n- _Fast_ builds using Vite.\n- Vite-powered tests with smart and instant watch mode\n\n## Setting up Vite\n\nTo create a new workspace, run `npx create-nx-workspace@latest --preset=npm`.\n\nTo add the Vite plugin to an existing workspace, run the following:\n\n{% tabs %}\n{% tab label=\"npm\" %}\n\n```shell\nnpm install -D @nrwl/vite\n```\n\n{% /tab %}\n{% tab label=\"yarn\" %}\n\n```shell\nyarn add -D @nrwl/vite\n```\n\n{% /tab %}\n{% tab label=\"pnpm\" %}\n\n```shell\npnpm install -D @nrwl/vite\n```\n\n{% /tab %}\n{% /tabs %}\n"
}
],
"generators": [],
"executors": []
}

View File

@ -1372,6 +1372,19 @@
} }
] ]
}, },
{
"name": "vite",
"id": "vite",
"description": "Vite package.",
"itemList": [
{
"name": "Overview",
"id": "overview",
"path": "/packages/vite",
"file": "shared/vite-plugin"
}
]
},
{ {
"name": "angular", "name": "angular",
"id": "angular", "id": "angular",

View File

@ -368,6 +368,13 @@
"path": "generated/packages/tao.json", "path": "generated/packages/tao.json",
"schemas": { "executors": [], "generators": [] } "schemas": { "executors": [], "generators": [] }
}, },
{
"name": "vite",
"packageName": "vite",
"description": "The Nx Plugin for building and testing applications using Vite (Early Release)",
"path": "generated/packages/vite.json",
"schemas": { "executors": [], "generators": [] }
},
{ {
"name": "web", "name": "web",
"packageName": "web", "packageName": "web",

View File

@ -0,0 +1,42 @@
The Nx plugin for [Vite](https://vitejs.dev/) and [Vitest](https://vitest.dev/).
{% callout type="warning" title="Early release plugin" %}
This Nx plugin is in active development and may not be ready for real-world use. The planned release date for the stable plugin is December, 2022.
{% /callout %}
Why should you use this plugin?
- Instant dev server start
- Lightning fast Hot-Module Reloading
- _Fast_ builds using Vite.
- Vite-powered tests with smart and instant watch mode
## Setting up Vite
To create a new workspace, run `npx create-nx-workspace@latest --preset=npm`.
To add the Vite plugin to an existing workspace, run the following:
{% tabs %}
{% tab label="npm" %}
```shell
npm install -D @nrwl/vite
```
{% /tab %}
{% tab label="yarn" %}
```shell
yarn add -D @nrwl/vite
```
{% /tab %}
{% tab label="pnpm" %}
```shell
pnpm install -D @nrwl/vite
```
{% /tab %}
{% /tabs %}

View File

@ -330,6 +330,7 @@ export function newProject({
`@nrwl/rollup`, `@nrwl/rollup`,
`@nrwl/react`, `@nrwl/react`,
`@nrwl/storybook`, `@nrwl/storybook`,
`@nrwl/vite`,
`@nrwl/web`, `@nrwl/web`,
`@nrwl/webpack`, `@nrwl/webpack`,
`@nrwl/react-native`, `@nrwl/react-native`,

11
e2e/vite/jest.config.ts Normal file
View File

@ -0,0 +1,11 @@
/* eslint-disable */
export default {
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
maxWorkers: 1,
globals: { 'ts-jest': { tsconfig: '<rootDir>/tsconfig.spec.json' } },
displayName: 'e2e-vite',
preset: '../../jest.preset.js',
};

34
e2e/vite/project.json Normal file
View File

@ -0,0 +1,34 @@
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "e2e/vite",
"projectType": "application",
"targets": {
"e2e": {
"executor": "nx:run-commands",
"options": {
"commands": [
{
"command": "yarn e2e-start-local-registry"
},
{
"command": "yarn e2e-build-package-publish"
},
{
"command": "nx run-e2e-tests e2e-vite"
}
],
"parallel": false
}
},
"run-e2e-tests": {
"executor": "@nrwl/jest:jest",
"options": {
"jestConfig": "e2e/vite/jest.config.ts",
"passWithNoTests": true,
"runInBand": true
},
"outputs": ["{workspaceRoot}/coverage/e2e/vite"]
}
},
"implicitDependencies": ["vite"]
}

15
e2e/vite/src/vite.test.ts Normal file
View File

@ -0,0 +1,15 @@
import { cleanupProject, newProject } from '@nrwl/e2e/utils';
describe('Vite Plugin', () => {
let proj: string;
beforeEach(() => (proj = newProject()));
afterEach(() => cleanupProject());
xit('should build applications', () => {});
xit('should serve applications in dev mode', () => {});
xit('should test applications', () => {});
});

13
e2e/vite/tsconfig.json Normal file
View File

@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": [],
"files": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}

View File

@ -0,0 +1,20 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"**/*.test.ts",
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.test.tsx",
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx",
"**/*.d.ts",
"jest.config.ts"
]
}

View File

@ -0,0 +1,25 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["./package.json", "./generators.json", "./executors.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nrwl/nx/nx-plugin-checks": "error"
}
}
]
}

31
packages/vite/.lib.swcrc Normal file
View File

@ -0,0 +1,31 @@
{
"jsc": {
"target": "es2017",
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true
},
"keepClassNames": true,
"externalHelpers": true,
"loose": true
},
"module": {
"type": "commonjs",
"strict": true,
"noInterop": true
},
"sourceMaps": true,
"exclude": [
"jest.config.ts",
".*.spec.tsx?$",
".*.test.tsx?$",
"./src/jest-setup.ts$",
"./**/jest-setup.ts$",
".*.js$"
]
}

13
packages/vite/README.md Normal file
View File

@ -0,0 +1,13 @@
<p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
{{links}}
<hr>
# Nx: Smart, Fast and Extensible Build System
Nx is a next generation build system with first class monorepo support and powerful integrations.
This package is a [Vite plugin for Nx](https://nx.dev/packages/vite).
{{content}}

View File

View File

@ -0,0 +1,4 @@
{
"builders": {},
"executors": {}
}

View File

@ -0,0 +1,6 @@
{
"name": "Nx Vite",
"version": "0.1",
"schematics": {},
"generators": {}
}

1
packages/vite/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './src/utils/versions';

View File

@ -0,0 +1,17 @@
const fs = require('fs');
// Reading the SWC compilation config and remove the "exclude"
// for the test files to be compiled by SWC
const { exclude: _, ...swcJestConfig } = JSON.parse(
fs.readFileSync(`${__dirname}/.lib.swcrc`, 'utf-8')
);
module.exports = {
displayName: 'vite',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['@swc/jest', swcJestConfig],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/packages/vite',
};

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,40 @@
{
"name": "@nrwl/vite",
"version": "0.0.1",
"private": false,
"description": "The Nx Plugin for building and testing applications using Vite (Early Release)",
"repository": {
"type": "git",
"url": "https://github.com/nrwl/nx.git",
"directory": "packages/vite"
},
"keywords": [
"Monorepo",
"Vite",
"Web",
"CLI"
],
"main": "./index.js",
"typings": "./index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
"bugs": {
"url": "https://github.com/nrwl/nx/issues"
},
"homepage": "https://nx.dev",
"schematics": "./generators.json",
"builders": "./executors.json",
"ng-update": {
"requirements": {},
"migrations": "./migrations.json"
},
"dependencies": {
"@nrwl/devkit": "file:../devkit",
"@nrwl/workspace": "file:../workspace",
"@swc/helpers": "^0.4.11",
"chalk": "4.1.0"
},
"publishConfig": {
"access": "public"
}
}

View File

@ -0,0 +1,87 @@
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/vite",
"projectType": "library",
"targets": {
"test": {
"executor": "@nrwl/jest:jest",
"options": {
"jestConfig": "packages/vite/jest.config.ts",
"passWithNoTests": true
},
"outputs": ["{workspaceRoot}/coverage/packages/vite"]
},
"build-base": {
"executor": "@nrwl/js:swc",
"options": {
"outputPath": "build/packages/vite",
"tsConfig": "packages/vite/tsconfig.lib.json",
"main": "packages/vite/index.ts",
"updateBuildableProjectDepsInPackageJson": false,
"assets": [
{
"input": "packages/vite",
"glob": "**/files/**",
"output": "/"
},
{
"input": "packages/vite",
"glob": "**/files/**/.gitkeep",
"output": "/"
},
{
"input": "packages/vite",
"glob": "**/*.json",
"ignore": ["**/tsconfig*.json", "project.json", ".eslintrc.json"],
"output": "/"
},
{
"input": "packages/vite",
"glob": "**/*.js",
"ignore": ["**/jest.config.js"],
"output": "/"
},
{
"input": "packages/vite",
"glob": "**/*.d.ts",
"output": "/"
},
{
"input": "",
"glob": "LICENSE",
"output": "/"
}
]
},
"outputs": ["{options.outputPath}"]
},
"build": {
"executor": "nx:run-commands",
"outputs": ["{workspaceRoot}/build/packages/vite"],
"options": {
"command": "node ./scripts/copy-readme.js vite"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": [
"packages/vite/**/*.ts",
"packages/vite/**/*.spec.ts",
"packages/vite/**/*_spec.ts",
"packages/vite/**/*.spec.tsx",
"packages/vite/**/*.spec.js",
"packages/vite/**/*.spec.jsx",
"packages/vite/**/*.d.ts",
"packages/vite/**/executors/**/schema.json",
"packages/vite/**/generators/**/schema.json",
"packages/vite/generators.json",
"packages/vite/executors.json",
"packages/vite/package.json",
"packages/vite/migrations.json"
]
},
"outputs": ["{options.outputFile}"]
}
}
}

View File

View File

View File

@ -0,0 +1 @@
export const nxVersion = require('../../package.json').version;

View File

@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs"
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}

View File

@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true
},
"include": ["**/*.ts"],
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"]
}

View File

@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
}

View File

@ -3,7 +3,7 @@ import * as depcheck from 'depcheck';
// Ignore packages that are defined here per package. // Ignore packages that are defined here per package.
// Note: If @babel/parser fails to parse a file, then its imports will not be detected. // Note: If @babel/parser fails to parse a file, then its imports will not be detected.
const IGNORE_MATCHES = { const IGNORE_MATCHES = {
'*': ['@nrwl/workspace', 'chalk', 'tslib'], '*': ['@nrwl/devkit', '@nrwl/workspace', 'chalk', 'tslib', '@swc/helpers'],
angular: ['@angular-devkit/schematics', '@schematics/angular', 'http-server'], angular: ['@angular-devkit/schematics', '@schematics/angular', 'http-server'],
cli: [], cli: [],
cypress: [], cypress: [],
@ -22,6 +22,7 @@ const IGNORE_MATCHES = {
rollup: [], rollup: [],
storybook: [], storybook: [],
nx: ['glob'], nx: ['glob'],
vite: [],
web: ['http-server'], web: ['http-server'],
webpack: [ webpack: [
// These are not being picked up because @babel/parser is failing on the files that import them. // These are not being picked up because @babel/parser is failing on the files that import them.

View File

@ -35,6 +35,7 @@
"e2e-storybook": "e2e/storybook", "e2e-storybook": "e2e/storybook",
"e2e-storybook-angular": "e2e/storybook-angular", "e2e-storybook-angular": "e2e/storybook-angular",
"e2e-utils": "e2e/utils", "e2e-utils": "e2e/utils",
"e2e-vite": "e2e/vite",
"e2e-web": "e2e/web", "e2e-web": "e2e/web",
"e2e-webpack": "e2e/webpack", "e2e-webpack": "e2e/webpack",
"e2e-workspace-create": "e2e/workspace-create", "e2e-workspace-create": "e2e/workspace-create",
@ -82,6 +83,7 @@
"storybook": "packages/storybook", "storybook": "packages/storybook",
"tao": "packages/tao", "tao": "packages/tao",
"typedoc-theme": "typedoc-theme", "typedoc-theme": "typedoc-theme",
"vite": "packages/vite",
"web": "packages/web", "web": "packages/web",
"webpack": "packages/webpack", "webpack": "packages/webpack",
"workspace": "packages/workspace" "workspace": "packages/workspace"