Skip to content

Commit

Permalink
fix(vite): add dts to build options (#13934)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Dec 22, 2022
1 parent 95fb804 commit 3bb773d
Show file tree
Hide file tree
Showing 13 changed files with 1,142 additions and 687 deletions.
3 changes: 1 addition & 2 deletions docs/generated/packages/vite/generators/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
},
"includeVitest": {
"type": "boolean",
"description": "Use vitest for the test suite.",
"hidden": true
"description": "Use vitest for the test suite."
},
"uiFramework": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`@nrwl/vite:configuration library mode should add config for building library 1`] = `
"
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
Expand All @@ -11,17 +11,19 @@ import { join } from 'path';
export default defineConfig({
plugins: [
dts({
plugins: [
dts({
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
// Faster builds by skipping tests. Set this to false to enable type checking.
skipDiagnostics: true,
}),
react(),
viteTsConfigPaths({
root: '../',
}),
],
react(),
viteTsConfigPaths({
root: '../',
}),
],
// Configuration for building your library.
// See: https://vitejs.dev/guide/build.html#library-mode
Expand All @@ -47,7 +49,7 @@ import { join } from 'path';

exports[`@nrwl/vite:configuration library mode should set up non buildable library correctly 1`] = `
"
/// <reference types=\\"vitest\\" />
/// <reference types=\\"vitest\\" />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
Expand All @@ -56,17 +58,19 @@ import { join } from 'path';
export default defineConfig({
plugins: [
dts({
plugins: [
dts({
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
// Faster builds by skipping tests. Set this to false to enable type checking.
skipDiagnostics: true,
}),
react(),
viteTsConfigPaths({
root: '../../',
}),
],
react(),
viteTsConfigPaths({
root: '../../',
}),
],
// Configuration for building your library.
// See: https://vitejs.dev/guide/build.html#library-mode
Expand Down Expand Up @@ -154,6 +158,115 @@ exports[`@nrwl/vite:configuration library mode should set up non buildable libra
"
`;

exports[`@nrwl/vite:configuration library mode should set up non buildable library which already has vite.config.ts correctly 1`] = `
"import dts from 'vite-plugin-dts';
import { join } from 'path';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
export default defineConfig({
// Configuration for building your library.
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
lib: {
// Could also be a dictionary or array of multiple entry points.
entry: 'src/index.ts',
name: 'react-lib-nonb-vitest',
fileName: 'index',
// Change this to the formats you want to support.
// Don't forgot to update your package.json as well.
formats: ['es', 'cjs']
},
rollupOptions: {
// External packages that should not be bundled into your library.
external: ['react', 'react-dom', 'react/jsx-runtime']
}
},plugins: [
...[
react(),
viteTsConfigPaths({
root: '../../',
}),
],
dts({
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
// Faster builds by skipping tests. Set this to false to enable type checking.
skipDiagnostics: true,
}),
],
test: {
globals: true,
cache: {
dir: '../../node_modules/.vitest',
},
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
},
});
"
`;

exports[`@nrwl/vite:configuration library mode should set up non buildable library which already has vite.config.ts correctly 2`] = `
"{
\\"projects\\": {
\\"react-lib-nonb-vitest\\": {
\\"$schema\\": \\"../../node_modules/nx/schemas/project-schema.json\\",
\\"root\\": \\"libs/react-lib-nonb-vitest\\",
\\"sourceRoot\\": \\"libs/react-lib-nonb-vitest/src\\",
\\"projectType\\": \\"library\\",
\\"architect\\": {
\\"lint\\": {
\\"builder\\": \\"@nrwl/linter:eslint\\",
\\"outputs\\": [
\\"{options.outputFile}\\"
],
\\"options\\": {
\\"lintFilePatterns\\": [
\\"libs/react-lib-nonb-vitest/**/*.{ts,tsx,js,jsx}\\"
]
}
},
\\"test\\": {
\\"builder\\": \\"@nrwl/vite:test\\",
\\"outputs\\": [
\\"{projectRoot}/coverage\\"
],
\\"options\\": {
\\"passWithNoTests\\": true,
\\"reportsDirectory\\": \\"{workspaceRoot}/coverage/{projectRoot}\\"
}
},
\\"build\\": {
\\"builder\\": \\"@nrwl/vite:build\\",
\\"outputs\\": [
\\"{options.outputPath}\\"
],
\\"defaultConfiguration\\": \\"production\\",
\\"options\\": {
\\"outputPath\\": \\"dist/libs/react-lib-nonb-vitest\\"
},
\\"configurations\\": {
\\"development\\": {
\\"mode\\": \\"development\\"
},
\\"production\\": {
\\"mode\\": \\"production\\"
}
}
}
},
\\"tags\\": []
}
},
\\"version\\": 1
}
"
`;

exports[`@nrwl/vite:configuration transform React app to use Vite by providing custom targets transform React app if supported executor is provided should transform workspace.json project config 1`] = `
"{
\\"projects\\": {
Expand Down Expand Up @@ -226,7 +339,7 @@ exports[`@nrwl/vite:configuration transform React app to use Vite by providing c

exports[`@nrwl/vite:configuration transform React app to use Vite should create vite.config file at the root of the app 1`] = `
"
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
Expand All @@ -238,13 +351,15 @@ exports[`@nrwl/vite:configuration transform React app to use Vite should create
port: 4200,
host: 'localhost',
},
plugins: [
react(),
viteTsConfigPaths({
root: '../../',
}),
],
plugins: [
react(),
viteTsConfigPaths({
root: '../../',
}),
],
Expand Down Expand Up @@ -360,6 +475,7 @@ exports[`@nrwl/vite:configuration transform Web app to use Vite should create vi
"
import { defineConfig } from 'vite';
import viteTsConfigPaths from 'vite-tsconfig-paths';
Expand All @@ -369,12 +485,15 @@ exports[`@nrwl/vite:configuration transform Web app to use Vite should create vi
port: 4200,
host: 'localhost',
},
plugins: [
viteTsConfigPaths({
root: '../../',
}),
],
plugins: [
viteTsConfigPaths({
root: '../../',
}),
],
Expand Down Expand Up @@ -478,7 +597,7 @@ exports[`@nrwl/vite:configuration transform Web app to use Vite should transform
exports[`@nrwl/vite:configuration vitest should create a vitest configuration if "includeVitest" is true 1`] = `
"
/// <reference types=\\"vitest\\" />
/// <reference types=\\"vitest\\" />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsConfigPaths from 'vite-tsconfig-paths';
Expand All @@ -490,13 +609,15 @@ exports[`@nrwl/vite:configuration vitest should create a vitest configuration if
port: 4200,
host: 'localhost',
},
plugins: [
react(),
viteTsConfigPaths({
root: '../../',
}),
],
plugins: [
react(),
viteTsConfigPaths({
root: '../../',
}),
],
test: {
Expand Down
25 changes: 25 additions & 0 deletions packages/vite/src/generators/configuration/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
mockAngularAppGenerator,
mockReactAppGenerator,
mockReactLibNonBuildableJestTestRunnerGenerator,
mockReactLibNonBuildableVitestRunnerGenerator,
mockReactMixedAppGenerator,
mockUnknownAppGenerator,
mockWebAppGenerator,
Expand Down Expand Up @@ -344,5 +345,29 @@ describe('@nrwl/vite:configuration', () => {

expect(tree.read('workspace.json', 'utf-8')).toMatchSnapshot();
});

it('should set up non buildable library which already has vite.config.ts correctly', async () => {
const { Confirm } = require('enquirer');
const confirmSpy = jest.spyOn(Confirm.prototype, 'run');
confirmSpy.mockResolvedValue(true);
expect.assertions(2);

mockReactLibNonBuildableVitestRunnerGenerator(tree);

try {
await viteConfigurationGenerator(tree, {
uiFramework: 'react',
project: 'react-lib-nonb-vitest',
includeVitest: true,
});
expect(
tree.read('libs/react-lib-nonb-vitest/vite.config.ts', 'utf-8')
).toMatchSnapshot();

expect(tree.read('workspace.json', 'utf-8')).toMatchSnapshot();
} catch (e) {
throw new Error('Should not throw error');
}
});
});
});
3 changes: 1 addition & 2 deletions packages/vite/src/generators/configuration/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
},
"includeVitest": {
"type": "boolean",
"description": "Use vitest for the test suite.",
"hidden": true
"description": "Use vitest for the test suite."
},
"uiFramework": {
"type": "string",
Expand Down
Loading

1 comment on commit 3bb773d

@vercel
Copy link

@vercel vercel bot commented on 3bb773d Dec 22, 2022

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-nrwl.vercel.app
nx.dev
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app

Please sign in to comment.