angular/packages/core/schematics/rollup.config.js
Paul Gschwendtner 185b7801ee build: migrate packages/core/schematics to ts_project (#61420)
Migrates `packages/core/schematics` to `ts_project`. As part of this,
this commit cleans up some of the mixed module types and tsconfigs in
the folder. A single tsconfig (and it's test variant) are now used.

For the shipped schematics, we explicitly use the `.cjs` extension, so
that the bundles are properly recognized as CommonJS; even if they are
part of the `type: module` `@angular/core` package.

The `package.json` with `type: commonjs` is removed from
`packages/core/schematics` as it's no longer needed given the explicit
extension & caused issues as schematics are compiled with ESM but are
only later bundled for shipping & some tests as ESM.

PR Close #61420
2025-05-16 15:53:27 +00:00

65 lines
1.4 KiB
JavaScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
const {nodeResolve} = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
/** Removed license banners from input files. */
const stripBannerPlugin = {
name: 'strip-license-banner',
transform(code, _filePath) {
const banner = /(\/\**\s+\*\s@license.*?\*\/)/s.exec(code);
if (!banner) {
return;
}
const [bannerContent] = banner;
const pos = code.indexOf(bannerContent);
if (pos !== -1) {
const result = code.slice(0, pos) + code.slice(pos + bannerContent.length);
return {
code: result.trimStart(),
map: null,
};
}
return {
code: code,
map: null,
};
},
};
const banner = `'use strict';
/**
* @license Angular v0.0.0-PLACEHOLDER
* (c) 2010-2025 Google LLC. https://angular.io/
* License: MIT
*/`;
const plugins = [
nodeResolve({
jail: process.cwd(),
}),
stripBannerPlugin,
commonjs(),
];
/** @type {import('rollup').RollupOptions} */
const config = {
plugins,
external: ['typescript', 'tslib', /@angular-devkit\/.+/],
output: {
exports: 'auto',
chunkFileNames: '[name]-[hash].cjs',
entryFileNames: '[name].cjs',
banner,
},
};
module.exports = config;