Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): remove hard dependencies to @nrwl/vite and @nrwl/webpack #14408

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
"@nrwl/js": "file:../js",
"@nrwl/linter": "file:../linter",
"@nrwl/rollup": "file:../rollup",
"@nrwl/vite": "file:../vite",
"@nrwl/webpack": "file:../webpack",
"@nrwl/workspace": "file:../workspace",
"babel-plugin-const-enum": "^1.0.1",
"babel-plugin-macros": "^2.8.0",
Expand Down
16 changes: 14 additions & 2 deletions packages/web/src/executors/dev-server/dev-server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
* This is here for backwards-compat.
* TODO(jack): remove in Nx 16.
*/
import { devServerExecutor, WebDevServerOptions } from '@nrwl/webpack';
import { ExecutorContext } from '@nrwl/devkit';

export { devServerExecutor, WebDevServerOptions };
export async function* devServerExecutor(
options: any,
context: ExecutorContext
) {
const { devServerExecutor: baseDevServerExecutor } = require('@nrwl/webpack');
yield* baseDevServerExecutor(
{
...options,
target: 'web',
},
context
);
}
export default devServerExecutor;
8 changes: 2 additions & 6 deletions packages/web/src/executors/webpack/webpack.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
* TODO(jack): Remove in Nx 16.
*/
import { ExecutorContext } from '@nrwl/devkit';
import type { WebpackExecutorOptions } from '@nrwl/webpack';
import { webpackExecutor as baseWebpackExecutor } from '@nrwl/webpack';

export async function* webpackExecutor(
options: WebpackExecutorOptions,
context: ExecutorContext
) {
export async function* webpackExecutor(options: any, context: ExecutorContext) {
const { webpackExecutor: baseWebpackExecutor } = require('@nrwl/webpack');
yield* baseWebpackExecutor(
{
...options,
Expand Down
11 changes: 8 additions & 3 deletions packages/web/src/generators/application/application.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { join } from 'path';
import { webpackProjectGenerator } from '@nrwl/webpack';
import { cypressProjectGenerator } from '@nrwl/cypress';
import {
addDependenciesToPackageJson,
addProjectConfiguration,
convertNxGenerator,
ensurePackage,
extractLayoutDirectory,
formatFiles,
generateFiles,
Expand All @@ -25,9 +25,8 @@ import { swcCoreVersion } from '@nrwl/js/src/utils/versions';
import { Linter, lintProjectGenerator } from '@nrwl/linter';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import { viteConfigurationGenerator, vitestGenerator } from '@nrwl/vite';

import { swcLoaderVersion } from '../../utils/versions';
import { nxVersion, swcLoaderVersion } from '../../utils/versions';
import { webInitGenerator } from '../init/init';
import { Schema } from './schema';

Expand Down Expand Up @@ -75,6 +74,8 @@ async function setupBundler(tree: Tree, options: NormalizedSchema) {
];

if (options.bundler === 'webpack') {
await ensurePackage(tree, '@nrwl/webpack', nxVersion);
const { webpackProjectGenerator } = require('@nrwl/webpack');
await webpackProjectGenerator(tree, {
project: options.projectName,
main,
Expand Down Expand Up @@ -194,6 +195,8 @@ export async function applicationGenerator(host: Tree, schema: Schema) {
await addProject(host, options);

if (options.bundler === 'vite') {
await ensurePackage(host, '@nrwl/vite', nxVersion);
const { viteConfigurationGenerator } = require('@nrwl/vite');
// We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
// See: https://vitejs.dev/guide/env-and-mode.html
host.delete(joinPathFragments(options.appProjectRoot, 'src/environments'));
Expand All @@ -209,6 +212,8 @@ export async function applicationGenerator(host: Tree, schema: Schema) {
}

if (options.bundler !== 'vite' && options.unitTestRunner === 'vitest') {
await ensurePackage(host, '@nrwl/vite', nxVersion);
const { vitestGenerator } = require('@nrwl/vite');
const vitestTask = await vitestGenerator(host, {
uiFramework: 'none',
project: options.projectName,
Expand Down