Files
awesome-cordova-plugins/scripts/build/esbuild-plugins.js
T
Daniel Sogl f47561fd7c feat: migrate from Webpack to esbuild for optimized builds
- Updated build process to use esbuild, enhancing performance and reducing bundle size.
- Introduced custom esbuild plugins to replicate Webpack functionality, including removal of duplicate tslib helpers.
- Replaced the previous build script for ES5 with a new optimized version using esbuild.
- Added support for TypeScript in esbuild configuration, ensuring compatibility with existing code.
- Removed Webpack-related dependencies and configurations from package.json and renovate.json.

This transition aims to streamline the build process and improve overall efficiency.
2025-06-07 16:02:05 +02:00

37 lines
1.1 KiB
JavaScript

// Custom esbuild plugins to replace webpack functionality
/**
* Plugin to remove duplicate tslib helpers that TypeScript might emit
* Works with both .js and .ts files for comprehensive coverage
*/
const removeTslibHelpersPlugin = {
name: 'remove-tslib-helpers',
setup(build) {
// Handle both JavaScript and TypeScript files
build.onLoad({ filter: /\.(js|ts)$/ }, async (args) => {
const fs = require('fs');
const path = require('path');
const contents = await fs.promises.readFile(args.path, 'utf8');
// Remove the __extends method that is added automatically by typescript
const transformedContents = contents.replace(
/var\s__extends\s=\s\(this\s&&[\sa-z\._\(\)\|{}=:\[\]&,;?]+}\)\(\);/i,
''
);
// Determine the correct loader based on file extension
const ext = path.extname(args.path);
const loader = ext === '.ts' ? 'ts' : 'js';
return {
contents: transformedContents,
loader: loader,
};
});
},
};
module.exports = {
removeTslibHelpersPlugin,
};