Revert "feat: migrate from Webpack to esbuild for optimized builds"

This reverts commit f47561fd7c.
This commit is contained in:
Daniel Sogl
2025-06-10 17:15:53 +02:00
parent 216e553f63
commit 963d4a2f3e
10 changed files with 1328 additions and 953 deletions
-70
View File
@@ -1,70 +0,0 @@
import { readJSONSync, writeFileSync } from 'fs-extra';
import { resolve } from 'path';
import { build } from 'esbuild';
import { minifiedConfig, unminifiedConfig } from '../build/esbuild.config';
import { ROOT } from '../build/helpers';
import { EMIT_PATH, InjectableClassEntry } from '../build/transformers/extract-injectables';
import { Logger } from '../logger';
const DIST = resolve(ROOT, 'dist');
const INDEX_PATH = resolve(DIST, 'index.ts');
const INJECTABLE_CLASSES = readJSONSync(EMIT_PATH).map((item: InjectableClassEntry) => {
// Convert file paths to TypeScript source files instead of compiled JS
item.file =
'./' +
item.file
.split(/[\/\\]+/)
.slice(-4, -1)
.join('/')
.replace('/dist/', '/src/'); // Point to source TypeScript files
return item;
});
function getPluginImport(entry: InjectableClassEntry) {
return `import { ${entry.className} } from '${entry.file}';`;
}
function createIndexFile() {
let fileContent = '';
fileContent += INJECTABLE_CLASSES.map(getPluginImport).join('\n');
fileContent += `\n\n// Global IonicNative object for browser usage\ndeclare global {\n interface Window {\n IonicNative: any;\n }\n}\n\n`;
fileContent += `window.IonicNative = {\n`;
fileContent += INJECTABLE_CLASSES.map((e) => e.className).join(',\n');
fileContent += '\n};\n\n';
fileContent += `// Bootstrap and Angular 1 integration\n`;
fileContent += `import './@awesome-cordova-plugins/core/bootstrap';\n`;
fileContent += `import { initAngular1 } from './@awesome-cordova-plugins/core/ng1';\n`;
fileContent += `\n// Check if platform is ready and initialize Angular 1 support\n`;
fileContent += `initAngular1(window.IonicNative);`;
writeFileSync(INDEX_PATH, fileContent, { encoding: 'utf-8' });
}
async function compile() {
Logger.profile('build-es5-optimized');
try {
// Build both minified and unminified versions in parallel
await Promise.all([
build({
...minifiedConfig,
entryPoints: [INDEX_PATH],
}),
build({
...unminifiedConfig,
entryPoints: [INDEX_PATH],
}),
]);
Logger.profile('build-es5-optimized');
Logger.info('Compiled ES5 bundles with esbuild native TypeScript support successfully.');
} catch (error) {
Logger.profile('build-es5-optimized');
Logger.error('Error occurred while compiling with esbuild:', error);
throw error;
}
}
createIndexFile();
compile();
+91
View File
@@ -0,0 +1,91 @@
import { readJSONSync, writeFileSync } from 'fs-extra';
import { resolve } from 'path';
import * as TerserPlugin from 'terser-webpack-plugin';
import * as unminifiedPlugin from 'unminified-webpack-plugin';
import { Configuration, DefinePlugin, ProvidePlugin, webpack } from 'webpack';
import { ROOT } from '../build/helpers';
import { cleanEmittedData, EMIT_PATH, InjectableClassEntry } from '../build/transformers/extract-injectables';
import { Logger } from '../logger';
const DIST = resolve(ROOT, 'dist');
const INDEX_PATH = resolve(DIST, 'index.js');
const INJECTABLE_CLASSES = readJSONSync(EMIT_PATH).map((item: InjectableClassEntry) => {
item.file =
'./' +
item.file
.split(/[\/\\]+/)
.slice(-4, -1)
.join('/');
return item;
});
const webpackConfig: Configuration = {
mode: 'production',
entry: INDEX_PATH,
devtool: 'source-map',
target: 'web',
output: {
path: DIST,
filename: 'awesome-cordova-plugins.min.js',
},
resolve: {
modules: ['node_modules'],
extensions: ['.js'],
alias: {
'@awesome-cordova-plugins/core': resolve(DIST, '@awesome-cordova-plugins/core/index.js'),
},
},
module: {
rules: [
{
test: /\.js$/,
use: resolve(ROOT, 'scripts/build/remove-tslib-helpers.js'),
},
],
},
plugins: [
new ProvidePlugin({
__extends: ['tslib', '__extends'],
}),
new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new unminifiedPlugin(),
],
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
},
};
function getPluginImport(entry: InjectableClassEntry) {
return `import { ${entry.className} } from '${entry.file}';`;
}
function createIndexFile() {
let fileContent = '';
fileContent += INJECTABLE_CLASSES.map(getPluginImport).join('\n');
fileContent += `\nwindow.IonicNative = {\n`;
fileContent += INJECTABLE_CLASSES.map((e) => e.className).join(',\n');
fileContent += '\n};\n';
fileContent += `require('./@awesome-cordova-plugins/core/bootstrap').checkReady();\n`;
fileContent += `require('./@awesome-cordova-plugins/core/ng1').initAngular1(window.IonicNative);`;
writeFileSync(INDEX_PATH, fileContent, { encoding: 'utf-8' });
}
function compile() {
Logger.profile('build-es5');
webpack(webpackConfig, (err, stats) => {
Logger.profile('build-es5');
if (err) Logger.error('Error occurred while compiling with Webpack', err);
else {
Logger.info('Compiled ES5 file with Webpack successfully.');
}
cleanEmittedData();
});
}
createIndexFile();
compile();