Skip to content

feat: bundler config refactor #5840

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

Merged
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
4 changes: 2 additions & 2 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ injector.require(
injector.requirePublic("cleanupService", "./services/cleanup-service");

injector.require(
"webpackCompilerService",
"./services/webpack/webpack-compiler-service",
"bundlerCompilerService",
"./services/bundler/bundler-compiler-service",
);

injector.require(
Expand Down
3 changes: 3 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const SCOPED_TNS_CORE_MODULES = "@nativescript/core";
export const TNS_CORE_THEME_NAME = "nativescript-theme-core";
export const SCOPED_TNS_CORE_THEME_NAME = "@nativescript/theme";
export const WEBPACK_PLUGIN_NAME = "@nativescript/webpack";
export const RSPACK_PLUGIN_NAME = "@nativescript/rspack";
export const TNS_CORE_MODULES_WIDGETS_NAME = "tns-core-modules-widgets";
export const UI_MOBILE_BASE_NAME = "@nativescript/ui-mobile-base";
export const TNS_ANDROID_RUNTIME_NAME = "tns-android";
Expand All @@ -36,6 +37,7 @@ export const XML_FILE_EXTENSION = ".xml";
export const PLATFORMS_DIR_NAME = "platforms";
export const HOOKS_DIR_NAME = "hooks";
export const WEBPACK_CONFIG_NAME = "webpack.config.js";
export const RSPACK_CONFIG_NAME = "rspack.config.js";
export const TSCCONFIG_TNS_JSON_NAME = "tsconfig.tns.json";
export const KARMA_CONFIG_NAME = "karma.conf.js";
export const LIB_DIR_NAME = "lib";
Expand Down Expand Up @@ -223,6 +225,7 @@ export const FILES_CHANGE_EVENT_NAME = "filesChangeEvent";
export const INITIAL_SYNC_EVENT_NAME = "initialSyncEvent";
export const PREPARE_READY_EVENT_NAME = "prepareReadyEvent";
export const WEBPACK_COMPILATION_COMPLETE = "webpackCompilationComplete";
export const BUNDLER_COMPILATION_COMPLETE = "bundlerCompilationComplete";

export class DebugCommandErrors {
public static UNABLE_TO_USE_FOR_DEVICE_AND_EMULATOR =
Expand Down
16 changes: 8 additions & 8 deletions lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class PrepareController extends EventEmitter {
private $prepareNativePlatformService: IPrepareNativePlatformService,
private $projectChangesService: IProjectChangesService,
private $projectDataService: IProjectDataService,
private $webpackCompilerService: IWebpackCompilerService,
private $bundlerCompilerService: IBundlerCompilerService,
private $watchIgnoreListService: IWatchIgnoreListService,
private $analyticsService: IAnalyticsService,
private $markingModeService: IMarkingModeService,
Expand Down Expand Up @@ -117,8 +117,8 @@ export class PrepareController extends EventEmitter {
this.watchersData[projectDir][platformLowerCase] &&
this.watchersData[projectDir][platformLowerCase].hasWebpackCompilerProcess
) {
await this.$webpackCompilerService.stopWebpackCompiler(platformLowerCase);
this.$webpackCompilerService.removeListener(
await this.$bundlerCompilerService.stopBundlerCompiler(platformLowerCase);
this.$bundlerCompilerService.removeListener(
WEBPACK_COMPILATION_COMPLETE,
this.webpackCompilerHandler,
);
Expand Down Expand Up @@ -177,7 +177,7 @@ export class PrepareController extends EventEmitter {
prepareData,
);
} else {
await this.$webpackCompilerService.compileWithoutWatch(
await this.$bundlerCompilerService.compileWithoutWatch(
platformData,
projectData,
prepareData,
Expand Down Expand Up @@ -296,15 +296,15 @@ export class PrepareController extends EventEmitter {
};

this.webpackCompilerHandler = handler.bind(this);
this.$webpackCompilerService.on(
this.$bundlerCompilerService.on(
WEBPACK_COMPILATION_COMPLETE,
this.webpackCompilerHandler,
);

this.watchersData[projectData.projectDir][
platformData.platformNameLowerCase
].hasWebpackCompilerProcess = true;
await this.$webpackCompilerService.compileWithWatch(
await this.$bundlerCompilerService.compileWithWatch(
platformData,
projectData,
prepareData,
Expand Down Expand Up @@ -560,7 +560,7 @@ export class PrepareController extends EventEmitter {
if (this.pausedFileWatch) {
for (const watcher of watchers) {
for (const platform in watcher) {
await this.$webpackCompilerService.stopWebpackCompiler(platform);
await this.$bundlerCompilerService.stopBundlerCompiler(platform);
watcher[platform].hasWebpackCompilerProcess = false;
}
}
Expand All @@ -569,7 +569,7 @@ export class PrepareController extends EventEmitter {
for (const platform in watcher) {
const args = watcher[platform].prepareArguments;
watcher[platform].hasWebpackCompilerProcess = true;
await this.$webpackCompilerService.compileWithWatch(
await this.$bundlerCompilerService.compileWithWatch(
args.platformData,
args.projectData,
args.prepareData,
Expand Down
13 changes: 12 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export interface IOSLocalSPMPackage extends IOSSPMPackageBase {
}

export type IOSSPMPackage = IOSRemoteSPMPackage | IOSLocalSPMPackage;
export type BundlerType = "webpack" | "rspack" | "vite";

interface INsConfigIOS extends INsConfigPlaform {
discardUncaughtJsExceptions?: boolean;
Expand Down Expand Up @@ -183,6 +184,7 @@ interface INsConfig {
overridePods?: string;
webpackConfigPath?: string;
bundlerConfigPath?: string;
bundler?: BundlerType;
ios?: INsConfigIOS;
android?: INsConfigAndroid;
visionos?: INSConfigVisionOS;
Expand Down Expand Up @@ -216,7 +218,16 @@ interface IProjectData extends ICreateProjectData {
* Value is true when project has nativescript.config and it has `shared: true` in it.
*/
isShared: boolean;

/**
* Specifies the bundler used to build the application.
*
* - `"webpack"`: Uses Webpack for traditional bundling.
* - `"rspack"`: Uses Rspack for fast bundling.
* - `"vite"`: Uses Vite for fast bundling.
*
* @default "webpack"
*/
bundler: BundlerType;
/**
* @deprecated Use bundlerConfigPath
* Defines the path to the configuration file passed to webpack process.
Expand Down
9 changes: 9 additions & 0 deletions lib/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parseJson } from "./common/helpers";
import { EOL } from "os";
import { cache } from "./common/decorators";
import {
BundlerType,
INsConfig,
IProjectConfigService,
IProjectData,
Expand Down Expand Up @@ -100,6 +101,7 @@ export class ProjectData implements IProjectData {
public isShared: boolean;
public webpackConfigPath: string;
public bundlerConfigPath: string;
public bundler: BundlerType;
public initialized: boolean;

constructor(
Expand Down Expand Up @@ -213,6 +215,13 @@ export class ProjectData implements IProjectData {
this.nsConfig && this.nsConfig.bundlerConfigPath
? path.resolve(this.projectDir, this.nsConfig.bundlerConfigPath)
: null;
this.bundler =
this.nsConfig && this.nsConfig.bundler
? (path.resolve(
this.projectDir,
this.nsConfig.bundler,
) as BundlerType)
: "webpack";
return;
}

Expand Down
Loading