Skip to content

Commit f6953f0

Browse files
clydinKeen Yee Liau
authored and
Keen Yee Liau
committed
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
1 parent c119a40 commit f6953f0

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

Diff for: packages/angular_devkit/build_angular/src/dev-server/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export function serveWebpackBrowser(
209209

210210
const entrypoints = generateEntryPoints({ scripts, styles });
211211
const moduleEntrypoints = buildBrowserFeatures.isDifferentialLoadingNeeded()
212-
? entrypoints
212+
? generateEntryPoints({ scripts: [], styles })
213213
: [];
214214

215215
webpackConfig.plugins.push(

Diff for: packages/angular_devkit/build_angular/test/dev-server/index_spec_large.ts

+45
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import { workspaces } from '@angular-devkit/core';
89
import fetch from 'node-fetch'; // tslint:disable-line:no-implicit-dependencies
910
import { DevServerBuilderOutput } from '../../src/dev-server/index';
1011
import { createArchitect, host } from '../utils';
@@ -38,6 +39,50 @@ describe('Dev Server Builder index', () => {
3839
await run.stop();
3940
});
4041

42+
it(`does not add 'type="module"' to custom scripts when differential loading is needed`, async () => {
43+
host.writeMultipleFiles({
44+
browserslist: `
45+
last 1 chrome version
46+
IE 10
47+
`,
48+
'test.js': 'console.log("test");',
49+
});
50+
51+
const { workspace } = await workspaces.readWorkspace(host.root(), workspaces.createWorkspaceHost(host));
52+
const app = workspace.projects.get('app');
53+
if (!app) {
54+
fail('Test application "app" not found.');
55+
56+
return;
57+
}
58+
const target = app.targets.get('build');
59+
if (!target) {
60+
fail('Test application "app" target "build" not found.');
61+
62+
return;
63+
}
64+
if (!target.options) {
65+
target.options = {};
66+
}
67+
target.options.scripts = ['test.js'];
68+
await workspaces.writeWorkspace(workspace, workspaces.createWorkspaceHost(host));
69+
70+
const architect = (await createArchitect(host.root())).architect;
71+
const run = await architect.scheduleTarget(targetSpec);
72+
const output = (await run.result) as DevServerBuilderOutput;
73+
expect(output.success).toBe(true);
74+
const response = await fetch('http://localhost:4200/index.html');
75+
expect(await response.text()).toContain(
76+
'<script src="runtime.js" type="module"></script>' +
77+
'<script src="polyfills.js" type="module"></script>' +
78+
'<script src="styles.js" type="module"></script>' +
79+
'<script src="scripts.js"></script>' +
80+
'<script src="vendor.js" type="module"></script>' +
81+
'<script src="main.js" type="module"></script>',
82+
);
83+
await run.stop();
84+
});
85+
4186
it(`doesn't 'type="module"' when differential loading is not needed`, async () => {
4287
host.writeMultipleFiles({
4388
browserslist: `

0 commit comments

Comments
 (0)