Skip to content

Commit

Permalink
fix(nuxt): tsconfig types and output dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Feb 22, 2024
1 parent 5d6abe4 commit 59a97ad
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { defineNuxtConfig } from 'nuxt/config';
export default defineNuxtConfig({
workspaceDir: '../',
srcDir: 'src',
buildDir: '../dist/my-app/.nuxt',
devtools: { enabled: true },
devServer: {
host: 'localhost',
Expand All @@ -53,11 +52,6 @@ export default defineNuxtConfig({
vite: {
plugins: [nxViteTsPaths()],
},
nitro: {
output: {
dir: '../dist/my-app/.output',
},
},
});
"
`;
Expand All @@ -77,7 +71,7 @@ exports[`app generated files content - as-provided general application should co
"{
"compilerOptions": {},
"files": [],
"include": [],
"include": [".nuxt/nuxt.d.ts"],
"references": [
{
"path": "./tsconfig.app.json"
Expand Down Expand Up @@ -161,7 +155,7 @@ exports[`app generated files content - as-provided general application should co
"{
"compilerOptions": {},
"files": [],
"include": [],
"include": [".nuxt/nuxt.d.ts"],
"references": [
{
"path": "./tsconfig.app.json"
Expand Down Expand Up @@ -221,7 +215,6 @@ import { defineNuxtConfig } from 'nuxt/config';
export default defineNuxtConfig({
workspaceDir: '../',
srcDir: 'src',
buildDir: '../dist/myapp1/.nuxt',
devtools: { enabled: true },
devServer: {
host: 'localhost',
Expand All @@ -242,11 +235,6 @@ export default defineNuxtConfig({
vite: {
plugins: [nxViteTsPaths()],
},
nitro: {
output: {
dir: '../dist/myapp1/.output',
},
},
});
"
`;
Expand All @@ -259,7 +247,6 @@ import { defineNuxtConfig } from 'nuxt/config';
export default defineNuxtConfig({
workspaceDir: '../',
srcDir: 'src',
buildDir: '../dist/myapp3/.nuxt',
devtools: { enabled: true },
devServer: {
host: 'localhost',
Expand All @@ -280,11 +267,6 @@ export default defineNuxtConfig({
vite: {
plugins: [nxViteTsPaths()],
},
nitro: {
output: {
dir: '../dist/myapp3/.output',
},
},
});
"
`;
Expand All @@ -297,7 +279,6 @@ import { defineNuxtConfig } from 'nuxt/config';
export default defineNuxtConfig({
workspaceDir: '../',
srcDir: 'src',
buildDir: '../dist/myapp2/.nuxt',
devtools: { enabled: true },
devServer: {
host: 'localhost',
Expand All @@ -318,11 +299,6 @@ export default defineNuxtConfig({
vite: {
plugins: [nxViteTsPaths()],
},
nitro: {
output: {
dir: '../dist/myapp2/.output',
},
},
});
"
`;
Expand All @@ -335,7 +311,6 @@ import { defineNuxtConfig } from 'nuxt/config';
export default defineNuxtConfig({
workspaceDir: '../',
srcDir: 'src',
buildDir: '../dist/myapp4/.nuxt',
devtools: { enabled: true },
devServer: {
host: 'localhost',
Expand All @@ -354,11 +329,6 @@ export default defineNuxtConfig({
vite: {
plugins: [nxViteTsPaths()],
},
nitro: {
output: {
dir: '../dist/myapp4/.output',
},
},
});
"
`;
4 changes: 0 additions & 4 deletions packages/nuxt/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
tmpl: '',
style: options.style,
projectRoot: options.appProjectRoot,
buildDirectory: joinPathFragments(`dist/${options.appProjectRoot}/.nuxt`),
nitroOutputDir: joinPathFragments(
`dist/${options.appProjectRoot}/.output`
),
hasVitest: options.unitTestRunner === 'vitest',
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { defineNuxtConfig } from 'nuxt/config';
export default defineNuxtConfig({
workspaceDir: '<%= offsetFromRoot %>',
srcDir: 'src',
buildDir: '<%= offsetFromRoot %><%= buildDirectory %>',
devtools: { enabled: true },
devServer: {
host: 'localhost',
Expand All @@ -28,9 +27,4 @@ export default defineNuxtConfig({
nxViteTsPaths()
],
},
nitro: {
output: {
dir: '<%= offsetFromRoot %><%= nitroOutputDir %>',
},
},
});
20 changes: 7 additions & 13 deletions packages/nuxt/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ async function buildNuxtTargets(
buildDir: string;
} = await getInfoFromNuxtConfig(configFilePath, context, projectRoot);

const { buildOutputs } = getOutputs(
nuxtConfig,

projectRoot
);
const { buildOutputs } = getOutputs(nuxtConfig, projectRoot);

const namedInputs = getNamedInputs(projectRoot, context);

Expand Down Expand Up @@ -179,16 +175,14 @@ function getOutputs(
} {
let nuxtBuildDir = nuxtConfig?.buildDir;
if (nuxtConfig?.buildDir && basename(nuxtConfig?.buildDir) === '.nuxt') {
// buildDir will most probably be `../dist/my-app/.nuxt`
// we want the "general" outputPath to be `../dist/my-app`
// if buildDir exists, it will be `something/something/.nuxt`
// we want the "general" outputPath to be `something/something`
nuxtBuildDir = nuxtConfig.buildDir.replace(
basename(nuxtConfig.buildDir),
''
);
}
const buildOutputPath =
normalizeOutputPath(nuxtBuildDir, projectRoot) ??
'{workspaceRoot}/dist/{projectRoot}';
const buildOutputPath = normalizeOutputPath(nuxtBuildDir, projectRoot);

return {
buildOutputs: [buildOutputPath],
Expand All @@ -198,12 +192,12 @@ function getOutputs(
function normalizeOutputPath(
outputPath: string | undefined,
projectRoot: string
): string | undefined {
): string {
if (!outputPath) {
if (projectRoot === '.') {
return `{projectRoot}/dist`;
return `{projectRoot}`;
} else {
return `{workspaceRoot}/dist/{projectRoot}`;
return `{workspaceRoot}/{projectRoot}`;
}
} else {
if (isAbsolute(outputPath)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/utils/create-ts-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function createTsConfig(
const json = {
compilerOptions: {},
files: [],
include: [],
include: ['.nuxt/nuxt.d.ts'],
references: [
{
path: './tsconfig.app.json',
Expand Down

0 comments on commit 59a97ad

Please sign in to comment.