Skip to content

Commit

Permalink
feat(rspack): move logic for withWeb to applyWebConfig and bring in l…
Browse files Browse the repository at this point in the history
…ine with webpack (#28803)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
`withWeb` from `@nx/rspack` is not reflective of what `@nx/webpack`
does.


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Bring `withWeb` in line with `@nx/webpack`

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
Coly010 authored Nov 7, 2024
1 parent 2c9fc57 commit fd2e8d0
Show file tree
Hide file tree
Showing 25 changed files with 1,501 additions and 161 deletions.
10 changes: 4 additions & 6 deletions docs/generated/packages/rspack/executors/rspack.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
"type": "string",
"description": "The tsconfig file to build the project."
},
"typeCheck": {
"skipTypeChecking": {
"alias": "typeCheck",
"type": "boolean",
"description": "Skip the type checking."
},
"indexHtml": {
"type": "string",
"description": "The path to the index.html file."
"description": "Skip the type checking. Default is `false`."
},
"index": {
"alias": "indexHtml",
"type": "string",
"description": "HTML File which will be contain the application.",
"x-completion-type": "file",
Expand Down
10 changes: 7 additions & 3 deletions e2e/rspack/tests/rspack.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ describe('rspack e2e', () => {
});
expect(result).toContain('Successfully ran target build');
// Make sure expected files are present.
expect(listFiles(`dist/${project}`)).toHaveLength(5);
/**
* The files that are generated are:
* ["3rdpartylicenses.txt", "assets", "favicon.ico", "index.html", "main.bf7851e6.js", "runtime.e4294127.js"]
*/
expect(listFiles(`dist/${project}`)).toHaveLength(6);

result = runCLI(`test ${project}`);
expect(result).toContain('Successfully ran target test');
Expand All @@ -83,7 +87,7 @@ describe('rspack e2e', () => {
env: { NODE_ENV: 'production' },
});
expect(result).toContain('Successfully ran target build');
expect(listFiles(`dist/${project}`)).toHaveLength(5); // same length as before
expect(listFiles(`dist/${project}`)).toHaveLength(6); // same length as before

// Generate a new app and check that the files are correct
const app2 = uniq('app2');
Expand Down Expand Up @@ -116,7 +120,7 @@ describe('rspack e2e', () => {
});
expect(result).toContain('Successfully ran target build');
// Make sure expected files are present.
expect(listFiles(`dist/${app2}`)).toHaveLength(5);
expect(listFiles(`dist/${app2}`)).toHaveLength(6);

result = runCLI(`test ${app2}`);
expect(result).toContain('Successfully ran target test');
Expand Down
3 changes: 2 additions & 1 deletion packages/rspack/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"@nx/workspace",
// Imported types only
"@module-federation/sdk",
"@module-federation/enhanced"
"@module-federation/enhanced",
"css-loader"
]
}
]
Expand Down
19 changes: 13 additions & 6 deletions packages/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,27 @@
"@nx/devkit": "file:../devkit",
"@nx/web": "file:../web",
"@phenomnomnominal/tsquery": "~5.0.1",
"@rspack/core": "^1.0.4",
"@rspack/dev-server": "^1.0.4",
"@rspack/plugin-react-refresh": "^1.0.0",
"autoprefixer": "^10.4.9",
"chalk": "~4.1.0",
"css-loader": "^6.4.0",
"enquirer": "~2.3.6",
"express": "^4.19.2",
"http-proxy-middleware": "^3.0.3",
"less-loader": "11.1.0",
"license-webpack-plugin": "^4.0.2",
"loader-utils": "^2.0.3",
"sass": "^1.42.1",
"sass-loader": "^12.2.0",
"stylus-loader": "^7.1.0",
"style-loader": "^3.3.0",
"postcss-import": "~14.1.0",
"postcss-loader": "^8.1.1",
"@rspack/core": "^1.0.4",
"@rspack/dev-server": "^1.0.4",
"@rspack/plugin-react-refresh": "^1.0.0",
"chalk": "~4.1.0",
"postcss": "^8.4.38",
"tsconfig-paths": "^4.1.2",
"tslib": "^2.3.0"
"tslib": "^2.3.0",
"webpack-subresource-integrity": "^5.1.0"
},
"peerDependencies": {
"@module-federation/enhanced": "~0.6.0",
Expand Down
17 changes: 17 additions & 0 deletions packages/rspack/src/executors/rspack/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ export interface RspackExecutorSchema {
index?: string;
tsConfig?: string;
typeCheck?: boolean;
skipTypeChecking?: boolean;
outputPath?: string;
outputFileName?: string;
index?: string;
indexHtml?: string;
mode?: Mode;
watch?: boolean;
Expand All @@ -23,6 +25,13 @@ export interface RspackExecutorSchema {
generatePackageJson?: boolean;
}

export interface AssetGlobPattern {
glob: string;
input: string;
output: string;
ignore?: string[];
}

export interface FileReplacement {
replace: string;
with: string;
Expand All @@ -32,3 +41,11 @@ export interface OptimizationOptions {
scripts: boolean;
styles: boolean;
}

export interface NormalizedRspackExecutorSchema extends RspackExecutorSchema {
outputFileName: string;
assets: AssetGlobPattern[];
root: string;
projectRoot: string;
sourceRoot: string;
}
10 changes: 4 additions & 6 deletions packages/rspack/src/executors/rspack/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
"type": "string",
"description": "The tsconfig file to build the project."
},
"typeCheck": {
"skipTypeChecking": {
"alias": "typeCheck",
"type": "boolean",
"description": "Skip the type checking."
},
"indexHtml": {
"type": "string",
"description": "The path to the index.html file."
"description": "Skip the type checking. Default is `false`."
},
"index": {
"alias": "indexHtml",
"type": "string",
"description": "HTML File which will be contain the application.",
"x-completion-type": "file",
Expand Down
Loading

0 comments on commit fd2e8d0

Please sign in to comment.