From 34e55c6e98ce3e9bea6564bb98b09bbaf96a2832 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Wed, 3 Jul 2019 11:21:58 -0400 Subject: [PATCH] fix(@angular-devkit/build-angular): only add module script types to actual module scripts `ng serve` was errantly adding a module type to custom script bundles. These scripts may contain ES5 and non-strict compatible code and can therefore not be marked as module scripts. `ng build` already correctly operates in this fashion. Fixes #14952 --- .../build_angular/src/dev-server/index.ts | 2 +- .../test/dev-server/index_spec_large.ts | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/packages/angular_devkit/build_angular/src/dev-server/index.ts b/packages/angular_devkit/build_angular/src/dev-server/index.ts index f9f39164e260..a945b9b77053 100644 --- a/packages/angular_devkit/build_angular/src/dev-server/index.ts +++ b/packages/angular_devkit/build_angular/src/dev-server/index.ts @@ -209,7 +209,7 @@ export function serveWebpackBrowser( const entrypoints = generateEntryPoints({ scripts, styles }); const moduleEntrypoints = buildBrowserFeatures.isDifferentialLoadingNeeded() - ? entrypoints + ? generateEntryPoints({ scripts: [], styles }) : []; webpackConfig.plugins.push( diff --git a/packages/angular_devkit/build_angular/test/dev-server/index_spec_large.ts b/packages/angular_devkit/build_angular/test/dev-server/index_spec_large.ts index bf261a5b5987..9ef1269cc1dd 100644 --- a/packages/angular_devkit/build_angular/test/dev-server/index_spec_large.ts +++ b/packages/angular_devkit/build_angular/test/dev-server/index_spec_large.ts @@ -5,6 +5,7 @@ * 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 */ +import { workspaces } from '@angular-devkit/core'; import fetch from 'node-fetch'; // tslint:disable-line:no-implicit-dependencies import { DevServerBuilderOutput } from '../../src/dev-server/index'; import { createArchitect, host } from '../utils'; @@ -38,6 +39,50 @@ describe('Dev Server Builder index', () => { await run.stop(); }); + it(`does not add 'type="module"' to custom scripts when differential loading is needed`, async () => { + host.writeMultipleFiles({ + browserslist: ` + last 1 chrome version + IE 10 + `, + 'test.js': 'console.log("test");', + }); + + const { workspace } = await workspaces.readWorkspace(host.root(), workspaces.createWorkspaceHost(host)); + const app = workspace.projects.get('app'); + if (!app) { + fail('Test application "app" not found.'); + + return; + } + const target = app.targets.get('build'); + if (!target) { + fail('Test application "app" target "build" not found.'); + + return; + } + if (!target.options) { + target.options = {}; + } + target.options.scripts = ['test.js']; + await workspaces.writeWorkspace(workspace, workspaces.createWorkspaceHost(host)); + + const architect = (await createArchitect(host.root())).architect; + const run = await architect.scheduleTarget(targetSpec); + const output = (await run.result) as DevServerBuilderOutput; + expect(output.success).toBe(true); + const response = await fetch('http://localhost:4200/index.html'); + expect(await response.text()).toContain( + '' + + '' + + '' + + '' + + '' + + '', + ); + await run.stop(); + }); + it(`doesn't 'type="module"' when differential loading is not needed`, async () => { host.writeMultipleFiles({ browserslist: `