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

feat(rspack): add convert-webpack generator #28167

Merged
merged 1 commit into from
Oct 23, 2024
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
8 changes: 8 additions & 0 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -9941,6 +9941,14 @@
"children": [],
"isExternal": false,
"disableCollapsible": false
},
{
"id": "convert-webpack",
"path": "/nx-api/rspack/generators/convert-webpack",
"name": "convert-webpack",
"children": [],
"isExternal": false,
"disableCollapsible": false
}
],
"isExternal": false,
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/manifests/nx-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3000,6 +3000,15 @@
"originalFilePath": "/packages/rspack/src/generators/application/schema.json",
"path": "/nx-api/rspack/generators/application",
"type": "generator"
},
"/nx-api/rspack/generators/convert-webpack": {
"description": "Convert a webpack application to use rspack.",
"file": "generated/packages/rspack/generators/convert-webpack.json",
"hidden": false,
"name": "convert-webpack",
"originalFilePath": "/packages/rspack/src/generators/convert-webpack/schema.json",
"path": "/nx-api/rspack/generators/convert-webpack",
"type": "generator"
}
},
"path": "/nx-api/rspack"
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/packages-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2970,6 +2970,15 @@
"originalFilePath": "/packages/rspack/src/generators/application/schema.json",
"path": "rspack/generators/application",
"type": "generator"
},
{
"description": "Convert a webpack application to use rspack.",
"file": "generated/packages/rspack/generators/convert-webpack.json",
"hidden": false,
"name": "convert-webpack",
"originalFilePath": "/packages/rspack/src/generators/convert-webpack/schema.json",
"path": "rspack/generators/convert-webpack",
"type": "generator"
}
],
"githubRoot": "https://github.com/nrwl/nx/blob/master",
Expand Down
34 changes: 34 additions & 0 deletions docs/generated/packages/rspack/generators/convert-webpack.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "convert-webpack",
"factory": "./src/generators/convert-webpack/convert-webpack",
"schema": {
"$schema": "http://json-schema.org/schema",
"$id": "Rspack",
"title": "Nx Webpack to Rspack Generator",
"description": "Convert a Webpack project to Rspack.",
"type": "object",
"properties": {
"project": {
"type": "string",
"description": "The name of the project.",
"$default": { "$source": "argv", "index": 0 },
"x-dropdown": "project",
"x-prompt": "What is the name of the project to convert to rspack?",
"x-priority": "important"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"presets": []
},
"description": "Convert a webpack application to use rspack.",
"implementation": "/packages/rspack/src/generators/convert-webpack/convert-webpack.ts",
"aliases": [],
"hidden": false,
"path": "/packages/rspack/src/generators/convert-webpack/schema.json",
"type": "generator"
}
1 change: 1 addition & 0 deletions docs/shared/reference/sitemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@
- [init](/nx-api/rspack/generators/init)
- [preset](/nx-api/rspack/generators/preset)
- [application](/nx-api/rspack/generators/application)
- [convert-webpack](/nx-api/rspack/generators/convert-webpack)
- [storybook](/nx-api/storybook)
- [documents](/nx-api/storybook/documents)
- [Overview](/nx-api/storybook/documents/overview)
Expand Down
51 changes: 51 additions & 0 deletions e2e/react/src/react-module-federation.rspack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,57 @@ describe('React Rspack Module Federation', () => {
}
}, 500_000);

it('should generate host and remote apps in webpack, convert to rspack and use playwright for e2es', async () => {
const shell = uniq('shell');
const remote1 = uniq('remote1');

runCLI(
`generate @nx/react:host ${shell} --remotes=${remote1} --bundler=webpack --e2eTestRunner=playwright --style=css --no-interactive --skipFormat`
);

runCLI(
`generate @nx/rspack:convert-webpack ${shell} --skipFormat --no-interactive`
);
runCLI(
`generate @nx/rspack:convert-webpack ${remote1} --skipFormat --no-interactive`
);

updateFile(
`apps/${shell}-e2e/src/example.spec.ts`,
stripIndents`
import { test, expect } from '@playwright/test';
test('should display welcome message', async ({page}) => {
await page.goto("/");
expect(await page.locator('h1').innerText()).toContain('Welcome');
});

test('should load remote 1', async ({page}) => {
await page.goto("/${remote1}");
expect(await page.locator('h1').innerText()).toContain('${remote1}');
});
`
);

if (runE2ETests()) {
const e2eResultsSwc = await runCommandUntil(
`e2e ${shell}-e2e`,
(output) => output.includes('Successfully ran target e2e for project')
);

await killProcessAndPorts(e2eResultsSwc.pid, readPort(shell));

const e2eResultsTsNode = await runCommandUntil(
`e2e ${shell}-e2e`,
(output) =>
output.includes('Successfully ran target e2e for project'),
{
env: { NX_PREFER_TS_NODE: 'true' },
}
);
await killProcessAndPorts(e2eResultsTsNode.pid, readPort(shell));
}
}, 500_000);

it('should have interop between webpack host and rspack remote', async () => {
const shell = uniq('shell');
const remote1 = uniq('remote1');
Expand Down
5 changes: 5 additions & 0 deletions packages/rspack/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"aliases": ["app"],
"x-type": "application",
"description": "React application generator."
},
"convert-webpack": {
"factory": "./src/generators/convert-webpack/convert-webpack",
"schema": "./src/generators/convert-webpack/schema.json",
"description": "Convert a webpack application to use rspack."
}
}
}
Loading