|
| 1 | +//@ts-nocheck |
| 2 | + |
| 3 | +const esbuild = require('esbuild'); |
| 4 | +const path = require('path'); |
| 5 | +const fs = require('fs'); |
| 6 | +const { moduleFederationPlugin } = require('@module-federation/esbuild/plugin'); |
| 7 | + |
| 8 | +async function buildProject(projectName, watch) { |
| 9 | + const tsConfig = 'tsconfig.json'; |
| 10 | + const outputPath = path.join('dist', projectName); |
| 11 | + |
| 12 | + fs.rmSync(outputPath, { force: true, recursive: true }); |
| 13 | + |
| 14 | + await esbuild.build({ |
| 15 | + entryPoints: [path.join(projectName, 'main.ts')], |
| 16 | + outdir: outputPath, |
| 17 | + bundle: true, |
| 18 | + platform: 'browser', |
| 19 | + format: 'esm', |
| 20 | + mainFields: ['es2020', 'browser', 'module', 'main'], |
| 21 | + conditions: ['es2022', 'es2015', 'module'], |
| 22 | + resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'], |
| 23 | + loader: { '.ts': 'ts' }, |
| 24 | + tsconfig: tsConfig, |
| 25 | + splitting: true, |
| 26 | + plugins: [ |
| 27 | + moduleFederationPlugin( |
| 28 | + require(path.join('../', projectName, 'federation.config.js')), |
| 29 | + ), |
| 30 | + ], |
| 31 | + watch, |
| 32 | + }); |
| 33 | + |
| 34 | + ['index.html', 'favicon.ico', 'styles.css'].forEach((file) => { |
| 35 | + fs.copyFileSync(path.join(projectName, file), path.join(outputPath, file)); |
| 36 | + }); |
| 37 | +} |
| 38 | + |
| 39 | +module.exports = { buildProject }; |
0 commit comments