2019-04-17 10:43:31 +00:00
|
|
|
const readFileSync = require('fs').readFileSync;
|
|
|
|
|
const writeFileSync = require('fs').writeFileSync;
|
|
|
|
|
const resolve = require('path').resolve;
|
|
|
|
|
const Terser = require('terser');
|
|
|
|
|
|
|
|
|
|
|
2021-09-20 20:12:21 +00:00
|
|
|
async function test() {
|
|
|
|
|
const outputPath = resolve(__dirname, './core.min.js');
|
2023-03-16 10:05:31 +00:00
|
|
|
const pathToCoreFesm2020 = resolve(__dirname, './node_modules/@angular/core/fesm2022/core.mjs');
|
|
|
|
|
const coreFesm2022Content = readFileSync(pathToCoreFesm2020, 'utf8');
|
2021-09-20 20:12:21 +00:00
|
|
|
|
|
|
|
|
const GLOBAL_DEFS_FOR_TERSER = (await import('@angular/compiler-cli')).GLOBAL_DEFS_FOR_TERSER;
|
|
|
|
|
|
|
|
|
|
// Ensure that Terser global_defs exported by compiler-cli work.
|
|
|
|
|
const terserOpts = {
|
|
|
|
|
compress: {
|
|
|
|
|
module: true,
|
|
|
|
|
global_defs: GLOBAL_DEFS_FOR_TERSER
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-03-16 10:05:31 +00:00
|
|
|
const result = await Terser.minify(coreFesm2022Content, terserOpts);
|
2021-09-20 20:12:21 +00:00
|
|
|
writeFileSync(outputPath, result.code);
|
|
|
|
|
|
|
|
|
|
for (const def of Object.keys(GLOBAL_DEFS_FOR_TERSER)) {
|
|
|
|
|
if (result.code.includes(def)) {
|
|
|
|
|
throw `'${def}' should have been removed from core bundle, but was still there.\n` +
|
2019-04-17 10:43:31 +00:00
|
|
|
`See output at ${outputPath}.`;
|
2021-09-20 20:12:21 +00:00
|
|
|
}
|
2019-04-17 10:43:31 +00:00
|
|
|
}
|
2021-09-20 20:12:21 +00:00
|
|
|
|
|
|
|
|
console.info('Output looks good.')
|
2020-05-06 04:35:44 +00:00
|
|
|
}
|
2021-09-20 20:12:21 +00:00
|
|
|
|
|
|
|
|
test().catch(e => {
|
|
|
|
|
console.error(e);
|
|
|
|
|
process.exitCode = 1;
|
|
|
|
|
});
|