-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nextjs): add fileReplacements to the builder config
- Loading branch information
1 parent
3cf5b99
commit 2f72133
Showing
17 changed files
with
373 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { MockBuilderContext } from '@nrwl/workspace/testing'; | ||
import * as build from 'next/dist/build'; | ||
import { getMockContext } from '../../utils/testing'; | ||
import { NextBuildBuilderOptions } from '../../utils/types'; | ||
import { run } from './build.impl'; | ||
|
||
jest.mock('next/dist/build'); | ||
|
||
describe('Next.js Builder', () => { | ||
let context: MockBuilderContext; | ||
let options: NextBuildBuilderOptions; | ||
|
||
beforeEach(async () => { | ||
context = await getMockContext(); | ||
|
||
options = { | ||
root: 'apps/wibble', | ||
outputPath: 'dist/apps/wibble', | ||
fileReplacements: [ | ||
{ | ||
replace: 'apps/wibble/src/environment.ts', | ||
with: 'apps/wibble/src/environment.prod.ts' | ||
} | ||
] | ||
}; | ||
|
||
jest.spyOn(build, 'default').mockReturnValue(Promise.resolve()); | ||
}); | ||
|
||
it('should call next build', async () => { | ||
await run(options, context).toPromise(); | ||
|
||
expect(build.default).toHaveBeenCalledWith( | ||
'/root/apps/wibble', | ||
expect.objectContaining({ | ||
distDir: '../../dist/apps/wibble', | ||
outdir: '../../dist/apps/wibble' | ||
}) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"title": "Next Build", | ||
"description": "Build a Next.js app", | ||
"type": "object", | ||
"properties": {}, | ||
"properties": { | ||
"root": { | ||
"description": "The source root", | ||
"type": "string" | ||
}, | ||
"outputPath": { | ||
"type": "string", | ||
"description": "The output path of the generated files." | ||
}, | ||
"fileReplacements": { | ||
"description": "Replace files with other files in the build.", | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"replace": { | ||
"type": "string" | ||
}, | ||
"with": { | ||
"type": "string" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": ["replace", "with"] | ||
}, | ||
"default": [] | ||
} | ||
}, | ||
"required": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
2f72133
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revisit this PR! The replacement doesn't work since you are providing relative url to nx-project by default in
packages/next/src/schematics/application/application.ts
, but requiring a relative path to nx-workspace for it to work!2f72133
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a bug in the app schematic. The paths in that file should be relative to the workspace root. I'll create a PR to fix it.