feat(mod_esbuild): Add alias support to esbuild bundling process

This commit is contained in:
2024-10-27 18:36:36 +01:00
parent 32b0781d72
commit 84854b0b40
6 changed files with 2455 additions and 2166 deletions

View File

@@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@git.zone/tsbundle',
version: '2.0.15',
version: '2.1.0',
description: 'a bundler using rollup for painless bundling of web projects'
}

View File

@@ -4,19 +4,32 @@ import * as interfaces from '../interfaces/index.js';
import { logger } from '../tsbundle.logging.js';
export class TsBundleProcess {
constructor() {
// Nothing here
}
public async getAliases() {
try {
const aliasObject: Record<string, string> = {};
const localTsConfig = plugins.smartfile.fs.toObjectSync(
plugins.path.join(paths.cwd, 'tsconfig.json')
);
if (localTsConfig.compilerOptions && localTsConfig.compilerOptions.paths) {
for (const alias of Object.keys(localTsConfig.compilerOptions.paths)) {
const aliasPath = localTsConfig.compilerOptions.paths[alias][0];
aliasObject[alias] = aliasPath;
}
}
return aliasObject;
} catch (error) {
return {};
}
}
/**
* creates a bundle for the test enviroment
*/
public async buildTest(
fromArg: string,
toArg: string,
argvArg: any
) {
public async buildTest(fromArg: string, toArg: string, argvArg: any) {
// create a bundle
const esbuild = await plugins.esbuild.build({
entryPoints: [fromArg],
@@ -27,22 +40,19 @@ export class TsBundleProcess {
entryNames: plugins.path.parse(toArg).name,
outdir: plugins.path.parse(toArg).dir,
// splitting: true,
tsconfig: paths.tsconfigPath
tsconfig: paths.tsconfigPath,
alias: await this.getAliases(),
});
}
/**
* creates a bundle for the production environment
*/
public async buildProduction(
fromArg: string,
toArg: string,
argvArg: any
) {
public async buildProduction(fromArg: string, toArg: string, argvArg: any) {
// create a bundle
console.log('esbuild specific:');
console.log(`from: ${fromArg}`);
console.log((`to: ${toArg}`));
console.log(`to: ${toArg}`);
const esbuild = await plugins.esbuild.build({
entryPoints: [fromArg],
bundle: true,
@@ -55,27 +65,30 @@ export class TsBundleProcess {
tsconfig: paths.tsconfigPath,
// splitting: true,
chunkNames: 'chunks/[name]-[hash]',
alias: await this.getAliases(),
});
}
}
const run = async () => {
console.log('running spawned compilation process');
const transportOptions: interfaces.IEnvTransportOptions = JSON.parse(process.env.transportOptions);
const transportOptions: interfaces.IEnvTransportOptions = JSON.parse(
process.env.transportOptions
);
console.log('=======> ESBUILD');
console.log(transportOptions);
process.chdir(transportOptions.cwd);
console.log(`switched to ${process.cwd()}`);
const tsbundleProcessInstance = new TsBundleProcess();
if (transportOptions.mode === 'test') {
console.log('building for test:')
console.log('building for test:');
tsbundleProcessInstance.buildTest(
plugins.smartpath.transform.makeAbsolute(transportOptions.from, process.cwd()),
plugins.smartpath.transform.makeAbsolute(transportOptions.to, process.cwd()),
transportOptions.argv
);
} else {
console.log('building for production:')
console.log('building for production:');
tsbundleProcessInstance.buildProduction(
plugins.smartpath.transform.makeAbsolute(transportOptions.from, process.cwd()),
plugins.smartpath.transform.makeAbsolute(transportOptions.to, process.cwd()),