angular/packages/compiler-cli/esbuild.config.js
Paul Gschwendtner c065f1b87a refactor: setup bundling for @angular/compiler-cli package (#43431)
All other frameworks packages are now using APF v13 and are strict
ESM packages. The compiler-cli does not use APF and is currently shipped
with its devmode ES5 CommonJS sources. This is problematic as CommonJS
cannot simply import from ECMAScript modules (like `@angular/compiler`).

To fix this we use a bundler that allows us to ship the compiler-cli as
a strict ESM package. Note: An ESM can import from an ESM without any
problems. This is what we need hre.

Unfortunatley we need a bundler here because converting the compiler-cli
to ESM is non-trivial as relative imports would need an explicit
`.js` extension. This work can be simplified by using a bundler that
avoids relative imports completely.

Note: This commit uses code-splitting to create multiple bundle
entry-points for `yarn ngc, `yarn ngcc` etc. This commit removed
the old `ivy-ngcc` entry-point that just printed an error message
(to reduce amount of bundles having to be configured).

PR Close #43431
2021-10-01 18:28:42 +00:00

24 lines
895 B
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.io/license
*/
module.exports = {
resolveExtensions: ['.mjs', '.js'],
// Note: `@bazel/esbuild` has a bug and does not pass-through the format from Starlark.
format: 'esm',
banner: {
// Workaround for: https://github.com/evanw/esbuild/issues/946
// We also define `__ESM_IMPORT_META_URL__` because we cannot use `import.meta.url`
// in our sources yet. The devmode CommonJS output will otherwise break.
// TODO: Remove this workaround in the future once devmode is ESM as well.
js: `
import {createRequire as __cjsCompatRequire} from 'module';
const require = __cjsCompatRequire(import.meta.url);
const __ESM_IMPORT_META_URL__ = import.meta.url;
`,
},
};