Skip to content

Commit

Permalink
feat(nuxt): fixed it
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Nov 1, 2023
1 parent 5bfa7d7 commit 035fb63
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 40 deletions.
2 changes: 1 addition & 1 deletion packages/nuxt/src/executors/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function* nuxtBuildExecutor(
extends: joinPathFragments(
context.root,
projectRoot,
'tsconfig.json'
'tsconfig.app.json'
),
},
},
Expand Down
1 change: 0 additions & 1 deletion packages/nuxt/src/executors/serve/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export interface NuxtServeExecutorOptions {
outputPath: string;
debug?: boolean;
dev?: boolean;
ssr?: boolean;
Expand Down
6 changes: 0 additions & 6 deletions packages/nuxt/src/executors/serve/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
"type": "string",
"description": "Host to listen on.",
"default": "localhost"
},
"outputPath": {
"type": "string",
"description": "The output path of the generated files.",
"x-completion-type": "directory",
"x-priority": "important"
}
},
"definitions": {},
Expand Down
7 changes: 1 addition & 6 deletions packages/nuxt/src/executors/serve/serve.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ export async function* nuxtServeExecutor(
await runCommand('dev', [projectRoot], {
overrides: {
workspaceDir: context.root,
buildDir: joinPathFragments(
context.root,
options.outputPath,
'.nuxt'
),
devServer: {
host: options.host,
port: options.port,
Expand All @@ -34,7 +29,7 @@ export async function* nuxtServeExecutor(
extends: joinPathFragments(
context.root,
projectRoot,
'tsconfig.json'
'tsconfig.app.json'
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ exports[`app generated files content - as-provided should configure tsconfig and
"targets": {
"serve": {
"executor": "@nx/nuxt:serve",
"outputs": ["{options.outputFile}"],
"options": {
"outputPath": "dist/my-app",
"port": 4200
}
},
"build": {
"executor": "@nx/nuxt:build",
"outputs": ["{options.outputFile}"],
"options": {
"outputPath": "dist/my-app"
}
Expand Down Expand Up @@ -87,6 +88,9 @@ exports[`app generated files content - as-provided should configure tsconfig and
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
Expand Down Expand Up @@ -115,6 +119,7 @@ exports[`app generated files content - as-provided should create all new files i
"my-app/src/public/favicon.ico",
"my-app/src/server/api/greet.ts",
"my-app/src/server/tsconfig.json",
"my-app/tsconfig.app.json",
"my-app/tsconfig.json",
".gitignore",
".eslintrc.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
getRelativePathToRootTsConfig(tree, options.appProjectRoot)
);

addServeTarget(tree, options.name, outputPath);
addServeTarget(tree, options.name);
addBuildTarget(tree, options.name, outputPath);

updateGitIgnore(tree);
Expand Down
18 changes: 10 additions & 8 deletions packages/nuxt/src/generators/application/files/src/app.vue__tmpl__
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<script setup lang="ts">
const route = useRoute();
</script>
<script setup lang="ts"></script>

<template>
<main>
<header>
<nav>
<NuxtLink to="/">Home</NuxtLink>
<NuxtLink to="/about">About</NuxtLink>
</nav>
<nav>
<NuxtLink to="/">
Home
</NuxtLink>
<NuxtLink to="/about">
About
</NuxtLink>
</nav>
</header>
<nuxt-page></nuxt-page>
<nuxt-page />
</main>
</template>

Expand Down
9 changes: 3 additions & 6 deletions packages/nuxt/src/generators/application/lib/add-targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import {
updateProjectConfiguration,
} from '@nx/devkit';

export function addServeTarget(
tree: Tree,
projectName: string,
outputPath: string
) {
export function addServeTarget(tree: Tree, projectName: string) {
const projectConfig = readProjectConfiguration(tree, projectName);
projectConfig.targets['serve'] = {
executor: '@nx/nuxt:serve',
outputs: ['{options.outputFile}'],
options: {
outputPath: outputPath,
port: 4200,
},
};
Expand All @@ -28,6 +24,7 @@ export function addBuildTarget(
const projectConfig = readProjectConfiguration(tree, projectName);
projectConfig.targets['build'] = {
executor: '@nx/nuxt:build',
outputs: ['{options.outputFile}'],
options: {
outputPath: outputPath,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ exports[`init should add nuxt dependencies 1`] = `
{
"dependencies": {},
"devDependencies": {
"@nuxt/devtools": "^0.8.0",
"@nuxt/devtools": "1.0.0-beta.0",
"@nuxt/ui-templates": "^1.3.1",
"@nx/js": "0.0.1",
"@nx/nuxt": "0.0.1",
"@nx/vite": "0.0.1",
"@swc-node/register": "~1.6.7",
"@swc/core": "~1.3.85",
"h3": "^1.8.2",
"nuxt": "3.6.5",
"nuxt": "^3.8.0",
"prettier": "^2.6.2",
"typescript": "~5.1.3",
"vue": "^3.3.4",
"vue-router": "^4.2.4",
"vue-tsc": "^1.8.8",
},
"name": "@proj/source",
}
Expand Down
9 changes: 5 additions & 4 deletions packages/nuxt/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,28 @@ import {
nuxtDevtoolsVersion,
nuxtVersion,
h3Version,
nuxtUiTemplatesVersion,
} from '../../utils/versions';
import {
lessVersion,
sassVersion,
vueRouterVersion,
vueVersion,
vueTscVersion,
} from '@nx/vue';
import { InitSchema } from './schema';

function updateDependencies(host: Tree, schema: InitSchema) {
let dependencies: { [key: string]: string } = {
vue: vueVersion,
};

let devDependencies: { [key: string]: string } = {
'@nx/nuxt': nxVersion,
'@nx/vite': nxVersion, // needed for the nxViteTsPaths plugin
'@nuxt/devtools': nuxtDevtoolsVersion,
'@nuxt/ui-templates': nuxtUiTemplatesVersion,
nuxt: nuxtVersion,
h3: h3Version,
vue: vueVersion,
'vue-router': vueRouterVersion,
'vue-tsc': vueTscVersion,
};

if (schema.style === 'scss') {
Expand Down
19 changes: 18 additions & 1 deletion packages/nuxt/src/utils/create-ts-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ export function createTsConfig(
},
relativePathToRootTsConfig: string
) {
createAppTsConfig(host, options);
const json = {
compilerOptions: {},
files: [],
include: [],
references: [],
references: [
{
path: './tsconfig.app.json',
},
],
} as any;

if (options.unitTestRunner !== 'none') {
Expand All @@ -38,3 +43,15 @@ export function createTsConfig(

writeJson(host, `${options.projectRoot}/tsconfig.json`, json);
}

function createAppTsConfig(host: Tree, options: { projectRoot: string }) {
const json = {
extends: './tsconfig.json',
compilerOptions: {
composite: true,
},
exclude: [],
};

writeJson(host, `${options.projectRoot}/tsconfig.app.json`, json);
}
13 changes: 10 additions & 3 deletions packages/nuxt/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ export const nxVersion = require('../../package.json').version;

// nuxt deps
export const h3Version = '^1.8.2';
export const nuxtVersion = '3.6.5';
export const nuxtKitVersion = '3.6.5';
export const nuxtDevtoolsVersion = '^0.8.0';
export const nuxtVersion = '^3.8.0';
export const nuxtDevtoolsVersion = '1.0.0-beta.0';
export const nuxtUiTemplatesVersion = '^1.3.1';

// linting deps
export const nuxtEslintConfigVersion = '0.2.0';

// TODO(katerina): nuxi version in package.json
/**
* Latest nuxi has a bug
*
* Nuxi version we use must be 3.6.5 until bug is fixed.
*/

0 comments on commit 035fb63

Please sign in to comment.