Skip to content

Commit

Permalink
fix(@ngtools/webpack): add cjs and mjs to passthrough files
Browse files Browse the repository at this point in the history
With this change we add `.mjs` and `.cjs` JS files passthough when `allowedJs` is not enabled.
  • Loading branch information
alan-agius4 committed Nov 3, 2021
1 parent d526e87 commit 5402f99
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/ngtools/webpack/src/ivy/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import * as path from 'path';
import type { LoaderContext } from 'webpack';
import { AngularPluginSymbol, FileEmitterCollection } from './symbol';

const JS_FILE_REGEXP = /\.[cm]?js$/;

export function angularWebpackLoader(this: LoaderContext<unknown>, content: string, map: string) {
const callback = this.async();
if (!callback) {
Expand All @@ -20,7 +22,7 @@ export function angularWebpackLoader(this: LoaderContext<unknown>, content: stri
this as LoaderContext<unknown> & { [AngularPluginSymbol]?: FileEmitterCollection }
)[AngularPluginSymbol];
if (!fileEmitter || typeof fileEmitter !== 'object') {
if (this.resourcePath.endsWith('.js')) {
if (JS_FILE_REGEXP.test(this.resourcePath)) {
// Passthrough for JS files when no plugin is used
this.callback(undefined, content, map);

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

0 comments on commit 5402f99

Please sign in to comment.