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

[DO NOT MERGE]rspack poc #2062

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
7,794 changes: 5,104 additions & 2,690 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 7 additions & 15 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,22 @@
"watch": "tsc -w"
},
"dependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.8",
"@module-federation/enhanced": "^0.6.3",
"@openshift/dynamic-plugin-sdk-webpack": "^4.1.0",
"@redhat-cloud-services/frontend-components-config-utilities": "^3.2.2",
"@redhat-cloud-services/tsc-transform-imports": "^1.0.12",
"@rspack/cli": "^1.0.4",
"@rspack/core": "^1.0.4",
"@swc/core": "^1.3.76",
"assert": "^2.0.0",
"axios": "^0.28.1 || ^1.7.0",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"chalk": "^4.1.2",
"clean-webpack-plugin": "^3.0.0",
"concurrently": "^7.4.0",
"css-loader": "^5.2.7",
"express": "^4.19.2",
"fork-ts-checker-webpack-plugin": "^7.2.13",
"git-revision-webpack-plugin": "^3.0.6",
"git-revision-webpack-plugin": "^5.0.0",
"glob": "^7.2.3",
"html-replace-webpack-plugin": "^2.6.0",
"html-webpack-plugin": "^5.5.0",
"http-server": "^14.0.0",
"https-proxy-agent": "^5.0.1",
"inquirer": "^8.2.4",
Expand All @@ -56,20 +54,14 @@
"mini-css-extract-plugin": "^2.7.3",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"react-refresh": "^0.14.0",
"sass": "^1.55.0",
"sass-loader": "^11.1.1",
"source-map-loader": "^3.0.1",
"sass-loader": "^16.0.1",
"stream-browserify": "^3.0.0",
"swc-loader": "^0.2.3",
"tree-kill": "^1.2.2",
"ts-loader": "^9.4.4",
"ts-loader": "^9.5.1",
"url": "^0.11.0",
"util": "^0.12.4",
"wait-on": "^7.2.0",
"webpack": "^5.88.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "4.15.1",
"yargs": "^17.6.2"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions packages/config/src/bin/build-script.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { LogType, fecLogger } from '@redhat-cloud-services/frontend-components-config-utilities';

import { getWebpackConfigPath, validateFECConfig } from './common';
import { getRSpackConfigPath, validateFECConfig } from './common';
const { resolve } = require('path');
import { spawn } from 'child_process';

export function buildScript(argv: { [name: string]: string }, cwd: string) {
let configPath;
if (typeof argv.webpackConfig !== 'undefined') {
configPath = getWebpackConfigPath(argv.webpackConfig, cwd);
if (typeof argv.rspackConfig !== 'undefined') {
configPath = getRSpackConfigPath(argv.rspackConfig, cwd);
} else {
// validate the FEC config only if a custom webpack config is not provided
// validate the FEC config only if a custom rspack config is not provided
validateFECConfig(cwd);
configPath = resolve(__dirname, './prod.webpack.config.js');
configPath = resolve(__dirname, './prod.rspack.config.js');
}
process.env.NODE_ENV = 'production';
const subprocess = spawn(`npm exec -- webpack -c ${configPath}`, [], {
const subprocess = spawn(`npm exec -- rspack -c ${configPath}`, [], {
stdio: [process.stdout, process.stdout, process.stdout],
cwd,
shell: true,
Expand Down
6 changes: 3 additions & 3 deletions packages/config/src/bin/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function validateFECConfig(cwd: string) {
process.env.FEC_CONFIG_PATH = configPath;
}

export function getWebpackConfigPath(path: string, cwd: string) {
export function getRSpackConfigPath(path: string, cwd: string) {
let configPath;
try {
configPath = resolve(cwd, path);
Expand All @@ -32,7 +32,7 @@ export function getWebpackConfigPath(path: string, cwd: string) {
return configPath;
} catch (error: any) {
if (configPath) {
fecLogger(LogType.error, `Unable to open webpack config at: "${configPath}"`);
fecLogger(LogType.error, `Unable to open RSpack config at: "${configPath}"`);
} else {
fecLogger(LogType.error, error);
throw 'FEC binary failed';
Expand All @@ -41,4 +41,4 @@ export function getWebpackConfigPath(path: string, cwd: string) {
}

module.exports.validateFECConfig = validateFECConfig;
module.exports.getWebpackConfigPath = getWebpackConfigPath;
module.exports.getRSpackConfigPath = getRSpackConfigPath;
25 changes: 14 additions & 11 deletions packages/config/src/bin/dev-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import inquirer from 'inquirer';
const { resolve } = require('path');
import { spawn } from 'child_process';
import treeKill from 'tree-kill';
import { getWebpackConfigPath, validateFECConfig } from './common';
import { getRSpackConfigPath, validateFECConfig } from './common';
import serveChrome from './serve-chrome';
import { LogType, fecLogger } from '@redhat-cloud-services/frontend-components-config-utilities';
const DEFAULT_CHROME_SERVER_PORT = 9998;
Expand All @@ -27,34 +27,35 @@ async function setEnv(cwd: string) {

async function devScript(
argv: {
webpackConfig?: string;
rspackConfig?: string;
clouddotEnv?: string;
port?: string;
chromeServerPort?: number | string;
},
cwd: string
) {
try {
console.log('Starting dev server...');
let localChrome = false;
let fecConfig: any = {};
let configPath;
let chromeHost;
if (typeof argv.webpackConfig !== 'undefined') {
configPath = getWebpackConfigPath(argv.webpackConfig, cwd);
if (typeof argv.rspackConfig !== 'undefined') {
configPath = getRSpackConfigPath(argv.rspackConfig, cwd);
if (typeof argv.chromeServerPort !== 'undefined') {
process.env.FEC_CHROME_PORT = `${argv.chromeServerPort}`;
} else {
fecLogger(LogType.info, `No chrome server port provided, using default port ${DEFAULT_CHROME_SERVER_PORT}`);
process.env.FEC_CHROME_PORT = `${DEFAULT_CHROME_SERVER_PORT}`;
}
} else {
// validate the FEC config only if a custom webpack config is not provided
// validate the FEC config only if a custom rspack config is not provided
validateFECConfig(cwd);
fecConfig = require(process.env.FEC_CONFIG_PATH!);
localChrome = fecConfig.localChrome;
process.env.FEC_CHROME_PORT = fecConfig.chromePort ?? DEFAULT_CHROME_SERVER_PORT;
chromeHost = fecConfig.chromeHost;
configPath = resolve(__dirname, './dev.webpack.config.js');
configPath = resolve(__dirname, './dev.rspack.config.js');
}

const clouddotEnvOptions = ['stage', 'prod'];
Expand All @@ -78,27 +79,29 @@ async function devScript(
process.env.PORT = argv.port;
}

let webpackProcess: ReturnType<typeof spawn> | undefined = undefined;
let rspackProcess: ReturnType<typeof spawn> | undefined = undefined;
let interceptorProcess: ReturnType<typeof spawn> | undefined = undefined;

if (!chromeHost) {
chromeHost = `${process.env.CLOUDOT_ENV === 'prod' ? 'prod' : 'stage'}.foo.redhat.com`;
}

process.env.FEC_CHROME_HOST = chromeHost;
console.log('CHrome host', chromeHost);

// ignore chrome server if a localChrome is provided
if (!localChrome && process.env.E2E_CI_RUN !== 'true') {
console.log('DIS?');
// get the directory if the build
// hsa to require here after all FEC env variables are set
const devConfig = require('./dev.webpack.config');
const devConfig = require('./dev.rspack.config');
const outputPath = devConfig.output?.path;
// start chrome frontend server
try {
const handleServerError = (error: Error) => {
fecLogger(LogType.error, error);
if (webpackProcess?.pid) {
treeKill(webpackProcess.pid, 'SIGKILL');
if (rspackProcess?.pid) {
treeKill(rspackProcess.pid, 'SIGKILL');
}

if (interceptorProcess?.pid) {
Expand All @@ -124,7 +127,7 @@ async function devScript(
}
}

webpackProcess = spawn(`npm exec -- webpack serve -c ${configPath}`, [], {
rspackProcess = spawn(`npm exec --offline -- rspack serve -c ${configPath}`, [], {
stdio: [process.stdout, process.stdout, process.stdout],
cwd,
shell: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ProxyConfigArrayItem } from 'webpack-dev-server';
import config, { FrontendEnv } from '../lib';
import FECConfiguration from '../lib/fec.config';
import commonPlugins from './webpack.plugins';
import commonPlugins from './rspack.plugins';
const fecConfig: FECConfiguration = require(process.env.FEC_CONFIG_PATH!);

type Configuration = import('webpack').Configuration;
type Configuration = import('@rspack/core').Configuration;

function parseRegexpURL(url: RegExp) {
return [new RegExp(url.toString())];
Expand Down Expand Up @@ -50,10 +50,10 @@ const internalProxyRoutes: { [endpoint: string]: ProxyConfigArrayItem } = {
: {}),
};

const { config: webpackConfig, plugins } = config({
const { config: rspackConfig, plugins } = config({
// do not hash files in dev env
useFileHash: false,
// enable webpack cache by default in dev env
// enable rspack cache by default in dev env
useCache: true,
...externalConfig,
routes: internalProxyRoutes,
Expand All @@ -66,7 +66,7 @@ const { config: webpackConfig, plugins } = config({
plugins.push(...commonPlugins, ...externalPlugins);

const devConfig: Configuration = {
...webpackConfig,
...rspackConfig,
plugins,
};

Expand Down
12 changes: 6 additions & 6 deletions packages/config/src/bin/fec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ function patchTs(dependencies: string) {

const argv = yargs
.usage('Usage: $0 <command> [options]')
.command('static', 'Serve webpack output without the webpack server', (yargs) => {
.command('static', 'Serve rspack output without the rspack server', (yargs) => {
yargs
.positional('config', {
type: 'string',
alias: 'c',
describe: 'Path to webpack config',
describe: 'Path to rspack config',
})
.option('port', {
type: 'number',
Expand All @@ -98,9 +98,9 @@ const argv = yargs
.command('patch-etc-hosts', "You may have to run this as 'sudo'. Setup your etc/hosts allow development hosts in your browser")
.command('dev', 'Start development server', (yargs) => {
yargs
.positional('webpack-config', {
.positional('rspack-config', {
type: 'string',
describe: 'Path to webpack config',
describe: 'Path to rspack config',
})
.option('port', {
type: 'number',
Expand All @@ -110,9 +110,9 @@ const argv = yargs
});
})
.command('build', 'Build production bundle', (yargs) => {
yargs.positional('webpack-config', {
yargs.positional('rspack-config', {
type: 'string',
describe: 'Path to webpack config',
describe: 'Path to rspack config',
});
})
.option('clouddotEnv', {
Expand Down
Loading