Skip to content

Commit 5402f99

Browse files
committed
fix(@ngtools/webpack): add cjs and mjs to passthrough files
With this change we add `.mjs` and `.cjs` JS files passthough when `allowedJs` is not enabled.
1 parent d526e87 commit 5402f99

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/ngtools/webpack/src/ivy/loader.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import * as path from 'path';
1010
import type { LoaderContext } from 'webpack';
1111
import { AngularPluginSymbol, FileEmitterCollection } from './symbol';
1212

13+
const JS_FILE_REGEXP = /\.[cm]?js$/;
14+
1315
export function angularWebpackLoader(this: LoaderContext<unknown>, content: string, map: string) {
1416
const callback = this.async();
1517
if (!callback) {
@@ -20,7 +22,7 @@ export function angularWebpackLoader(this: LoaderContext<unknown>, content: stri
2022
this as LoaderContext<unknown> & { [AngularPluginSymbol]?: FileEmitterCollection }
2123
)[AngularPluginSymbol];
2224
if (!fileEmitter || typeof fileEmitter !== 'object') {
23-
if (this.resourcePath.endsWith('.js')) {
25+
if (JS_FILE_REGEXP.test(this.resourcePath)) {
2426
// Passthrough for JS files when no plugin is used
2527
this.callback(undefined, content, map);
2628

@@ -36,7 +38,7 @@ export function angularWebpackLoader(this: LoaderContext<unknown>, content: stri
3638
.emit(this.resourcePath)
3739
.then((result) => {
3840
if (!result) {
39-
if (this.resourcePath.endsWith('.js')) {
41+
if (JS_FILE_REGEXP.test(this.resourcePath)) {
4042
// Return original content for JS files if not compiled by TypeScript ("allowJs")
4143
this.callback(undefined, content, map);
4244
} else {

0 commit comments

Comments
 (0)