| 4 | const Terser = require('terser'); |
| 5 | |
| 6 | async function test() { |
| 7 | const outputPath = resolve(__dirname, './core.min.js'); |
| 8 | const pathToCoreFesm2020 = resolve(__dirname, './node_modules/@angular/core/fesm2022/core.mjs'); |
| 9 | const coreFesm2022Content = readFileSync(pathToCoreFesm2020, 'utf8'); |
| 10 | |
| 11 | const GLOBAL_DEFS_FOR_TERSER = (await import('@angular/compiler-cli')).GLOBAL_DEFS_FOR_TERSER; |
| 12 | |
| 13 | // Ensure that Terser global_defs exported by compiler-cli work. |
| 14 | const terserOpts = { |
| 15 | compress: { |
| 16 | module: true, |
| 17 | global_defs: GLOBAL_DEFS_FOR_TERSER, |
| 18 | }, |
| 19 | }; |
| 20 | const result = await Terser.minify(coreFesm2022Content, terserOpts); |
| 21 | writeFileSync(outputPath, result.code); |
| 22 | |
| 23 | for (const def of Object.keys(GLOBAL_DEFS_FOR_TERSER)) { |
| 24 | if (result.code.includes(def)) { |
| 25 | throw ( |
| 26 | `'${def}' should have been removed from core bundle, but was still there.\n` + |
| 27 | `See output at ${outputPath}.` |
| 28 | ); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | console.info('Output looks good.'); |
| 33 | } |
| 34 | |
| 35 | test().catch((e) => { |
| 36 | console.error(e); |