Skip to content

Commit 77e2516

Browse files
committed
Merge branch 'feat/bundler-config' into pre/v9-combined-testing
2 parents 8013cee + e502c0b commit 77e2516

File tree

11 files changed

+418
-222
lines changed

11 files changed

+418
-222
lines changed

lib/bootstrap.ts

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 1 deletion
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";
@@ -222,7 +224,7 @@ export const CACACHE_DIRECTORY_NAME = "_cacache";
222224
export const FILES_CHANGE_EVENT_NAME = "filesChangeEvent";
223225
export const INITIAL_SYNC_EVENT_NAME = "initialSyncEvent";
224226
export const PREPARE_READY_EVENT_NAME = "prepareReadyEvent";
225-
export const WEBPACK_COMPILATION_COMPLETE = "webpackCompilationComplete";
227+
export const BUNDLER_COMPILATION_COMPLETE = "bundlerCompilationComplete";
226228

227229
export class DebugCommandErrors {
228230
public static UNABLE_TO_USE_FOR_DEVICE_AND_EMULATOR =

lib/controllers/prepare-controller.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import { hook } from "../common/helpers";
1313
import { injector } from "../common/yok";
1414
import {
1515
AnalyticsEventLabelDelimiter,
16+
BUNDLER_COMPILATION_COMPLETE,
1617
CONFIG_FILE_NAME_JS,
1718
CONFIG_FILE_NAME_TS,
1819
PACKAGE_JSON_FILE_NAME,
1920
PLATFORMS_DIR_NAME,
2021
PREPARE_READY_EVENT_NAME,
2122
SupportedPlatform,
2223
TrackActionNames,
23-
WEBPACK_COMPILATION_COMPLETE,
2424
} from "../constants";
2525
import { IOptions, IWatchIgnoreListService } from "../declarations";
2626
import {
@@ -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,9 +117,9 @@ 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(
122-
WEBPACK_COMPILATION_COMPLETE,
120+
await this.$bundlerCompilerService.stopBundlerCompiler(platformLowerCase);
121+
this.$bundlerCompilerService.removeListener(
122+
BUNDLER_COMPILATION_COMPLETE,
123123
this.webpackCompilerHandler,
124124
);
125125
this.watchersData[projectDir][
@@ -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(
300-
WEBPACK_COMPILATION_COMPLETE,
299+
this.$bundlerCompilerService.on(
300+
BUNDLER_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

Lines changed: 19 additions & 1 deletion
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;
@@ -182,6 +183,8 @@ interface INsConfig {
182183
shared?: boolean;
183184
overridePods?: string;
184185
webpackConfigPath?: string;
186+
bundlerConfigPath?: string;
187+
bundler?: BundlerType;
185188
ios?: INsConfigIOS;
186189
android?: INsConfigAndroid;
187190
visionos?: INSConfigVisionOS;
@@ -215,13 +218,28 @@ interface IProjectData extends ICreateProjectData {
215218
* Value is true when project has nativescript.config and it has `shared: true` in it.
216219
*/
217220
isShared: boolean;
218-
219221
/**
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;
231+
/**
232+
* @deprecated Use bundlerConfigPath
220233
* Defines the path to the configuration file passed to webpack process.
221234
* By default this is the webpack.config.js at the root of the application.
222235
* The value can be changed by setting `webpackConfigPath` in nativescript.config.
223236
*/
224237
webpackConfigPath: string;
238+
/**
239+
* Defines the path to the bundler configuration file passed to the compiler.
240+
* The value can be changed by setting `bundlerConfigPath` in nativescript.config.
241+
*/
242+
bundlerConfigPath: string;
225243
projectName: string;
226244

227245
/**

lib/project-data.ts

Lines changed: 29 additions & 19 deletions
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,
@@ -99,6 +100,8 @@ export class ProjectData implements IProjectData {
99100
public podfilePath: string;
100101
public isShared: boolean;
101102
public webpackConfigPath: string;
103+
public bundlerConfigPath: string;
104+
public bundler: BundlerType;
102105
public initialized: boolean;
103106

104107
constructor(
@@ -110,7 +113,7 @@ export class ProjectData implements IProjectData {
110113
private $logger: ILogger,
111114
private $injector: IInjector,
112115
private $androidResourcesMigrationService: IAndroidResourcesMigrationService,
113-
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants
116+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
114117
) {}
115118

116119
get projectConfig(): IProjectConfigService {
@@ -142,7 +145,7 @@ export class ProjectData implements IProjectData {
142145

143146
public initializeProjectDataFromContent(
144147
packageJsonContent: string,
145-
projectDir?: string
148+
projectDir?: string,
146149
): void {
147150
projectDir = projectDir || this.$projectHelper.projectDir || "";
148151
this.projectDir = projectDir;
@@ -157,7 +160,7 @@ export class ProjectData implements IProjectData {
157160
this.$errors.fail(
158161
`The project file ${this.projectFilePath} is corrupted. ${EOL}` +
159162
`Consider restoring an earlier version from your source control or backup.${EOL}` +
160-
`Additional technical info: ${err.toString()}`
163+
`Additional technical info: ${err.toString()}`,
161164
);
162165
}
163166

@@ -178,36 +181,43 @@ export class ProjectData implements IProjectData {
178181
this.appDirectoryPath = this.getAppDirectoryPath();
179182
this.appResourcesDirectoryPath = this.getAppResourcesDirectoryPath();
180183
this.androidManifestPath = this.getPathToAndroidManifest(
181-
this.appResourcesDirectoryPath
184+
this.appResourcesDirectoryPath,
182185
);
183186
this.gradleFilesDirectoryPath = path.join(
184187
this.appResourcesDirectoryPath,
185-
this.$devicePlatformsConstants.Android
188+
this.$devicePlatformsConstants.Android,
186189
);
187190
this.appGradlePath = path.join(
188191
this.gradleFilesDirectoryPath,
189-
constants.APP_GRADLE_FILE_NAME
192+
constants.APP_GRADLE_FILE_NAME,
190193
);
191194
this.infoPlistPath = path.join(
192195
this.appResourcesDirectoryPath,
193196
this.$devicePlatformsConstants.iOS,
194-
constants.INFO_PLIST_FILE_NAME
197+
constants.INFO_PLIST_FILE_NAME,
195198
);
196199
this.buildXcconfigPath = path.join(
197200
this.appResourcesDirectoryPath,
198201
this.$devicePlatformsConstants.iOS,
199-
constants.BUILD_XCCONFIG_FILE_NAME
202+
constants.BUILD_XCCONFIG_FILE_NAME,
200203
);
201204
this.podfilePath = path.join(
202205
this.appResourcesDirectoryPath,
203206
this.$devicePlatformsConstants.iOS,
204-
constants.PODFILE_NAME
207+
constants.PODFILE_NAME,
205208
);
206209
this.isShared = !!(this.nsConfig && this.nsConfig.shared);
207-
this.webpackConfigPath =
210+
211+
const webpackConfigPath =
208212
this.nsConfig && this.nsConfig.webpackConfigPath
209213
? path.resolve(this.projectDir, this.nsConfig.webpackConfigPath)
210214
: path.join(this.projectDir, "webpack.config.js");
215+
this.webpackConfigPath = webpackConfigPath;
216+
this.bundlerConfigPath =
217+
this.nsConfig && this.nsConfig.bundlerConfigPath
218+
? path.resolve(this.projectDir, this.nsConfig.bundlerConfigPath)
219+
: webpackConfigPath;
220+
this.bundler = this?.nsConfig?.bundler ?? "webpack";
211221
return;
212222
}
213223

@@ -217,7 +227,7 @@ export class ProjectData implements IProjectData {
217227
private getPathToAndroidManifest(appResourcesDir: string): string {
218228
const androidDirPath = path.join(
219229
appResourcesDir,
220-
this.$devicePlatformsConstants.Android
230+
this.$devicePlatformsConstants.Android,
221231
);
222232
const androidManifestDir =
223233
this.$androidResourcesMigrationService.hasMigrated(appResourcesDir)
@@ -230,13 +240,13 @@ export class ProjectData implements IProjectData {
230240
private errorInvalidProject(projectDir: string): void {
231241
const currentDir = path.resolve(".");
232242
this.$logger.trace(
233-
`Unable to find project. projectDir: ${projectDir}, options.path: ${this.$options.path}, ${currentDir}`
243+
`Unable to find project. projectDir: ${projectDir}, options.path: ${this.$options.path}, ${currentDir}`,
234244
);
235245

236246
// This is the case when no project file found
237247
this.$errors.fail(
238248
"No project found at or above '%s' and neither was a --path specified.",
239-
projectDir || this.$options.path || currentDir
249+
projectDir || this.$options.path || currentDir,
240250
);
241251
}
242252

@@ -291,7 +301,7 @@ export class ProjectData implements IProjectData {
291301

292302
private resolveToProjectDir(
293303
pathToResolve: string,
294-
projectDir?: string
304+
projectDir?: string,
295305
): string {
296306
if (!projectDir) {
297307
projectDir = this.projectDir;
@@ -306,7 +316,7 @@ export class ProjectData implements IProjectData {
306316

307317
@cache()
308318
private initializeProjectIdentifiers(
309-
config: INsConfig
319+
config: INsConfig,
310320
): Mobile.IProjectIdentifier {
311321
this.$logger.trace(`Initializing project identifiers. Config: `, config);
312322

@@ -341,18 +351,18 @@ export class ProjectData implements IProjectData {
341351
private getProjectType(): string {
342352
let detectedProjectType = _.find(
343353
ProjectData.PROJECT_TYPES,
344-
(projectType) => projectType.isDefaultProjectType
354+
(projectType) => projectType.isDefaultProjectType,
345355
).type;
346356

347357
const deps: string[] = _.keys(this.dependencies).concat(
348-
_.keys(this.devDependencies)
358+
_.keys(this.devDependencies),
349359
);
350360

351361
_.each(ProjectData.PROJECT_TYPES, (projectType) => {
352362
if (
353363
_.some(
354364
projectType.requiredDependencies,
355-
(requiredDependency) => deps.indexOf(requiredDependency) !== -1
365+
(requiredDependency) => deps.indexOf(requiredDependency) !== -1,
356366
)
357367
) {
358368
detectedProjectType = projectType.type;
@@ -366,7 +376,7 @@ export class ProjectData implements IProjectData {
366376
@cache()
367377
private warnProjectId(): void {
368378
this.$logger.warn(
369-
"[WARNING]: IProjectData.projectId is deprecated. Please use IProjectData.projectIdentifiers[platform]."
379+
"[WARNING]: IProjectData.projectId is deprecated. Please use IProjectData.projectIdentifiers[platform].",
370380
);
371381
}
372382
}

0 commit comments

Comments
 (0)