Skip to content

fix(@angular-devkit/build-angular): only add module script types to actual module scripts #14985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export function serveWebpackBrowser(

const entrypoints = generateEntryPoints({ scripts, styles });
const moduleEntrypoints = buildBrowserFeatures.isDifferentialLoadingNeeded()
? entrypoints
? generateEntryPoints({ scripts: [], styles })
: [];

webpackConfig.plugins.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
'<script src="runtime.js" type="module"></script>' +
'<script src="polyfills.js" type="module"></script>' +
'<script src="styles.js" type="module"></script>' +
'<script src="scripts.js"></script>' +
'<script src="vendor.js" type="module"></script>' +
'<script src="main.js" type="module"></script>',
);
await run.stop();
});

it(`doesn't 'type="module"' when differential loading is not needed`, async () => {
host.writeMultipleFiles({
browserslist: `
Expand Down