Skip to content

Commit 247f961

Browse files
authored
feat: bundler config refactor (#5840)
1 parent 0af7460 commit 247f961

File tree

10 files changed

+224
-172
lines changed

10 files changed

+224
-172
lines changed

lib/bootstrap.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ injector.require(
414414
injector.requirePublic("cleanupService", "./services/cleanup-service");
415415

416416
injector.require(
417-
"webpackCompilerService",
418-
"./services/webpack/webpack-compiler-service",
417+
"bundlerCompilerService",
418+
"./services/bundler/bundler-compiler-service",
419419
);
420420

421421
injector.require(

lib/constants.ts

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const SCOPED_TNS_CORE_MODULES = "@nativescript/core";
1616
export const TNS_CORE_THEME_NAME = "nativescript-theme-core";
1717
export const SCOPED_TNS_CORE_THEME_NAME = "@nativescript/theme";
1818
export const WEBPACK_PLUGIN_NAME = "@nativescript/webpack";
19+
export const RSPACK_PLUGIN_NAME = "@nativescript/rspack";
1920
export const TNS_CORE_MODULES_WIDGETS_NAME = "tns-core-modules-widgets";
2021
export const UI_MOBILE_BASE_NAME = "@nativescript/ui-mobile-base";
2122
export const TNS_ANDROID_RUNTIME_NAME = "tns-android";
@@ -36,6 +37,7 @@ export const XML_FILE_EXTENSION = ".xml";
3637
export const PLATFORMS_DIR_NAME = "platforms";
3738
export const HOOKS_DIR_NAME = "hooks";
3839
export const WEBPACK_CONFIG_NAME = "webpack.config.js";
40+
export const RSPACK_CONFIG_NAME = "rspack.config.js";
3941
export const TSCCONFIG_TNS_JSON_NAME = "tsconfig.tns.json";
4042
export const KARMA_CONFIG_NAME = "karma.conf.js";
4143
export const LIB_DIR_NAME = "lib";
@@ -223,6 +225,7 @@ export const FILES_CHANGE_EVENT_NAME = "filesChangeEvent";
223225
export const INITIAL_SYNC_EVENT_NAME = "initialSyncEvent";
224226
export const PREPARE_READY_EVENT_NAME = "prepareReadyEvent";
225227
export const WEBPACK_COMPILATION_COMPLETE = "webpackCompilationComplete";
228+
export const BUNDLER_COMPILATION_COMPLETE = "bundlerCompilationComplete";
226229

227230
export class DebugCommandErrors {
228231
public static UNABLE_TO_USE_FOR_DEVICE_AND_EMULATOR =

lib/controllers/prepare-controller.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class PrepareController extends EventEmitter {
6767
private $prepareNativePlatformService: IPrepareNativePlatformService,
6868
private $projectChangesService: IProjectChangesService,
6969
private $projectDataService: IProjectDataService,
70-
private $webpackCompilerService: IWebpackCompilerService,
70+
private $bundlerCompilerService: IBundlerCompilerService,
7171
private $watchIgnoreListService: IWatchIgnoreListService,
7272
private $analyticsService: IAnalyticsService,
7373
private $markingModeService: IMarkingModeService,
@@ -117,8 +117,8 @@ export class PrepareController extends EventEmitter {
117117
this.watchersData[projectDir][platformLowerCase] &&
118118
this.watchersData[projectDir][platformLowerCase].hasWebpackCompilerProcess
119119
) {
120-
await this.$webpackCompilerService.stopWebpackCompiler(platformLowerCase);
121-
this.$webpackCompilerService.removeListener(
120+
await this.$bundlerCompilerService.stopBundlerCompiler(platformLowerCase);
121+
this.$bundlerCompilerService.removeListener(
122122
WEBPACK_COMPILATION_COMPLETE,
123123
this.webpackCompilerHandler,
124124
);
@@ -177,7 +177,7 @@ export class PrepareController extends EventEmitter {
177177
prepareData,
178178
);
179179
} else {
180-
await this.$webpackCompilerService.compileWithoutWatch(
180+
await this.$bundlerCompilerService.compileWithoutWatch(
181181
platformData,
182182
projectData,
183183
prepareData,
@@ -296,15 +296,15 @@ export class PrepareController extends EventEmitter {
296296
};
297297

298298
this.webpackCompilerHandler = handler.bind(this);
299-
this.$webpackCompilerService.on(
299+
this.$bundlerCompilerService.on(
300300
WEBPACK_COMPILATION_COMPLETE,
301301
this.webpackCompilerHandler,
302302
);
303303

304304
this.watchersData[projectData.projectDir][
305305
platformData.platformNameLowerCase
306306
].hasWebpackCompilerProcess = true;
307-
await this.$webpackCompilerService.compileWithWatch(
307+
await this.$bundlerCompilerService.compileWithWatch(
308308
platformData,
309309
projectData,
310310
prepareData,
@@ -560,7 +560,7 @@ export class PrepareController extends EventEmitter {
560560
if (this.pausedFileWatch) {
561561
for (const watcher of watchers) {
562562
for (const platform in watcher) {
563-
await this.$webpackCompilerService.stopWebpackCompiler(platform);
563+
await this.$bundlerCompilerService.stopBundlerCompiler(platform);
564564
watcher[platform].hasWebpackCompilerProcess = false;
565565
}
566566
}
@@ -569,7 +569,7 @@ export class PrepareController extends EventEmitter {
569569
for (const platform in watcher) {
570570
const args = watcher[platform].prepareArguments;
571571
watcher[platform].hasWebpackCompilerProcess = true;
572-
await this.$webpackCompilerService.compileWithWatch(
572+
await this.$bundlerCompilerService.compileWithWatch(
573573
args.platformData,
574574
args.projectData,
575575
args.prepareData,

lib/definitions/project.d.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export interface IOSLocalSPMPackage extends IOSSPMPackageBase {
121121
}
122122

123123
export type IOSSPMPackage = IOSRemoteSPMPackage | IOSLocalSPMPackage;
124+
export type BundlerType = "webpack" | "rspack" | "vite";
124125

125126
interface INsConfigIOS extends INsConfigPlaform {
126127
discardUncaughtJsExceptions?: boolean;
@@ -183,6 +184,7 @@ interface INsConfig {
183184
overridePods?: string;
184185
webpackConfigPath?: string;
185186
bundlerConfigPath?: string;
187+
bundler?: BundlerType;
186188
ios?: INsConfigIOS;
187189
android?: INsConfigAndroid;
188190
visionos?: INSConfigVisionOS;
@@ -216,7 +218,16 @@ interface IProjectData extends ICreateProjectData {
216218
* Value is true when project has nativescript.config and it has `shared: true` in it.
217219
*/
218220
isShared: boolean;
219-
221+
/**
222+
* Specifies the bundler used to build the application.
223+
*
224+
* - `"webpack"`: Uses Webpack for traditional bundling.
225+
* - `"rspack"`: Uses Rspack for fast bundling.
226+
* - `"vite"`: Uses Vite for fast bundling.
227+
*
228+
* @default "webpack"
229+
*/
230+
bundler: BundlerType;
220231
/**
221232
* @deprecated Use bundlerConfigPath
222233
* Defines the path to the configuration file passed to webpack process.

lib/project-data.ts

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { parseJson } from "./common/helpers";
55
import { EOL } from "os";
66
import { cache } from "./common/decorators";
77
import {
8+
BundlerType,
89
INsConfig,
910
IProjectConfigService,
1011
IProjectData,
@@ -100,6 +101,7 @@ export class ProjectData implements IProjectData {
100101
public isShared: boolean;
101102
public webpackConfigPath: string;
102103
public bundlerConfigPath: string;
104+
public bundler: BundlerType;
103105
public initialized: boolean;
104106

105107
constructor(
@@ -213,6 +215,13 @@ export class ProjectData implements IProjectData {
213215
this.nsConfig && this.nsConfig.bundlerConfigPath
214216
? path.resolve(this.projectDir, this.nsConfig.bundlerConfigPath)
215217
: null;
218+
this.bundler =
219+
this.nsConfig && this.nsConfig.bundler
220+
? (path.resolve(
221+
this.projectDir,
222+
this.nsConfig.bundler,
223+
) as BundlerType)
224+
: "webpack";
216225
return;
217226
}
218227

0 commit comments

Comments
 (0)