Skip to content

Commit

Permalink
feat(rspack): migrate to rspack 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Aug 29, 2024
1 parent 291c751 commit 27f9df8
Show file tree
Hide file tree
Showing 9 changed files with 459 additions and 239 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
"@nx/vite": "19.5.7",
"@nx/workspace": "19.5.7",
"@phenomnomnominal/tsquery": "^5.0.1",
"@rspack/core": "^0.7.5",
"@rspack/dev-server": "^0.7.5",
"@rspack/core": "^1.0.0",
"@rspack/dev-server": "^1.0.0",
"@rspack/plugin-minify": "^0.7.5",
"@rspack/plugin-react-refresh": "^0.7.5",
"@rspack/plugin-react-refresh": "^1.0.0",
"@swc-node/register": "1.8.0",
"@types/fs-extra": "^11.0.1",
"@types/jest": "29.4.0",
Expand Down
17 changes: 17 additions & 0 deletions packages/rspack/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@
"alwaysAddToPackageJson": false
}
}
},
"19.7.0": {
"version": "19.7.0-beta.1",
"packages": {
"@rspack/core": {
"version": "^1.0.0",
"alwaysAddToPackageJson": false
},
"@rspack/dev-server": {
"version": "^1.0.0",
"alwaysAddToPackageJson": false
},
"@rspack/plugin-react-refresh": {
"version": "^1.0.0",
"alwaysAddToPackageJson": false
}
}
}
},
"version": "0.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"stylus-loader": "^7.1.0",
"postcss-loader": "^8.1.1",
"@nx/eslint": "^19.5.7",
"@rspack/core": "^0.7.5",
"@rspack/plugin-react-refresh": "^0.7.5",
"@rspack/core": "^1.0.0",
"@rspack/plugin-react-refresh": "^1.0.0",
"@rspack/plugin-minify": "^0.7.5",
"chalk": "~4.1.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default async function (
bundler: 'webpack',
name: options.name,
style: options.style,
directorsy: options.directory,
directory: options.directory,
tags: options.tags ?? '',
unitTestRunner: options.unitTestRunner,
e2eTestRunner: options.e2eTestRunner,
Expand Down Expand Up @@ -80,7 +80,7 @@ export default async function (
bundler: 'webpack',
name: options.name,
style: options.style,
directorsy: options.directory,
directory: options.directory,
tags: options.tags ?? '',
unitTestRunner: options.unitTestRunner,
e2eTestRunner: options.e2eTestRunner,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DefinePlugin } from '@rspack/core';
import { join } from 'path';
import { SharedConfigContext } from '../../model';
import {
ModuleFederationConfig,
Expand All @@ -21,11 +20,7 @@ export async function withModuleFederationForSSR(
});

return (config, { context }: SharedConfigContext) => {
config.context = join(
context.root,
context.projectGraph.nodes[context.projectName].data.root
);
config.target = false;
config.target = 'async-node';
config.output.uniqueName = options.name;
config.optimization = {
...(config.optimization ?? {}),
Expand All @@ -34,7 +29,7 @@ export async function withModuleFederationForSSR(

config.plugins.push(
// eslint-disable-next-line @typescript-eslint/no-var-requires
new (require('@module-federation/node').UniversalFederationPlugin)(
new (require('@module-federation/enhanced/rspack').ModuleFederationPlugin)(
{
name: options.name,
filename: 'remoteEntry.js',
Expand All @@ -43,9 +38,6 @@ export async function withModuleFederationForSSR(
shared: {
...sharedDependencies,
},
library: {
type: 'commonjs-module',
},
isServer: true,
/**
* Apply user-defined config overrides
Expand All @@ -56,11 +48,16 @@ export async function withModuleFederationForSSR(
!options.disableNxRuntimeLibraryControlPlugin
? [
...(configOverride?.runtimePlugins ?? []),
require.resolve('@module-federation/node/runtimePlugin'),
require.resolve(
'@nx/rspack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'
),
]
: configOverride?.runtimePlugins,
: [
...(configOverride?.runtimePlugins ?? []),
require.resolve('@module-federation/node/runtimePlugin'),
],
virtualRuntimeEntry: true,
},
{}
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
import type { Configuration } from '@rspack/core';
import { DefinePlugin } from '@rspack/core';
import { join } from 'path';
import { SharedConfigContext } from '../../model';
import {
ModuleFederationConfig,
Expand Down Expand Up @@ -34,10 +33,6 @@ export async function withModuleFederation(
config: Configuration,
{ context }: SharedConfigContext
): Configuration {
config.context = join(
context.root,
context.projectGraph.nodes[context.projectName].data.root
);
config.output.uniqueName = options.name;
config.output.publicPath = 'auto';

Expand Down Expand Up @@ -88,6 +83,7 @@ export async function withModuleFederation(
),
]
: configOverride?.runtimePlugins,
virtualRuntimeEntry: true,
}),
sharedLibraries.getReplacementPlugin()
);
Expand Down
6 changes: 3 additions & 3 deletions packages/rspack/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const rspackCoreVersion = '^0.7.5';
export const rspackDevServerVersion = '^0.7.5';
export const rspackCoreVersion = '^1.0.0';
export const rspackDevServerVersion = '^1.0.0';

export const rspackPluginMinifyVersion = '^0.7.5';
export const rspackPluginReactRefreshVersion = '^0.7.5';
export const rspackPluginReactRefreshVersion = '^1.0.0';
export const lessLoaderVersion = '~11.1.3';

export const reactVersion = '~18.2.0';
Expand Down
19 changes: 13 additions & 6 deletions packages/rspack/src/utils/with-nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@rspack/core';
import { LicenseWebpackPlugin } from 'license-webpack-plugin';
import * as path from 'path';
import { join } from 'path';
import { GeneratePackageJsonPlugin } from '../plugins/generate-package-json-plugin';
import { getCopyPatterns } from './get-copy-patterns';
import { SharedConfigContext } from './model';
Expand Down Expand Up @@ -91,18 +92,17 @@ export function withNx(_opts = {}) {
...config,
target: options.target,
mode: options.mode,
context: context.root,
entry: {},
context: join(
context.root,
context.projectGraph.nodes[context.projectName].data.root
),
devtool:
options.sourceMap === 'hidden'
? ('hidden-source-map' as const)
: options.sourceMap
? ('source-map' as const)
: (false as const),
entry: {
main: {
import: [path.join(context.root, options.main)],
},
},
output: {
path: path.join(context.root, options.outputPath),
publicPath: '/',
Expand Down Expand Up @@ -190,6 +190,13 @@ export function withNx(_opts = {}) {
},
};

const mainEntry = options.main
? options.outputFileName
? path.parse(options.outputFileName).name
: 'main'
: 'main';
updated.entry[mainEntry] = path.resolve(context.root, options.main);

return updated;
};
}
Loading

0 comments on commit 27f9df8

Please sign in to comment.