-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(polyfills): move polyfills to own entry point (#3812)
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only. This PR loads polyfills as a separate entry point, before everything else. Extra documentation also added to polyfills.ts. Fix #2752 Fix #3309 Fix #4140
- Loading branch information
1 parent
72f0d72
commit 08bb738
Showing
14 changed files
with
100 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,9 @@ | |
"main": { | ||
"type": "string" | ||
}, | ||
"polyfills": { | ||
"type": "string" | ||
}, | ||
"test": { | ||
"type": "string" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,36 @@ | ||
export function packageChunkSort(packages: string[]) { | ||
return function sort(left: any, right: any) { | ||
let leftIndex = packages.indexOf(left.names[0]); | ||
let rightindex = packages.indexOf(right.names[0]); | ||
import { ExtraEntry, extraEntryParser } from '../models/webpack-build-utils'; | ||
|
||
if ( leftIndex < 0 || rightindex < 0) { | ||
// Unknown packages are loaded last | ||
return 1; | ||
// Sort chunks according to a predefined order: | ||
// inline, polyfills, all scripts, all styles, vendor, main | ||
export function packageChunkSort(appConfig: any) { | ||
let entryPoints = ['inline', 'polyfills']; | ||
|
||
const pushExtraEntries = (extraEntry: ExtraEntry) => { | ||
if (entryPoints.indexOf(extraEntry.entry) === -1) { | ||
entryPoints.push(extraEntry.entry); | ||
} | ||
}; | ||
|
||
if (appConfig.scripts) { | ||
extraEntryParser(appConfig.scripts, './', 'scripts').forEach(pushExtraEntries); | ||
} | ||
|
||
if (appConfig.styles) { | ||
extraEntryParser(appConfig.styles, './', 'styles').forEach(pushExtraEntries); | ||
} | ||
|
||
entryPoints.push(...['vendor', 'main']); | ||
|
||
return function sort(left: any, right: any) { | ||
let leftIndex = entryPoints.indexOf(left.names[0]); | ||
let rightindex = entryPoints.indexOf(right.names[0]); | ||
|
||
if (leftIndex > rightindex) { | ||
return 1; | ||
} else if (leftIndex < rightindex) { | ||
return -1; | ||
} else { | ||
return 0; | ||
} | ||
|
||
return -1; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { expectFileToMatch } from '../../utils/fs'; | ||
import { ng } from '../../utils/process'; | ||
import { oneLineTrim } from 'common-tags'; | ||
|
||
export default function () { | ||
return Promise.resolve() | ||
.then(() => ng('build')) | ||
// files were created successfully | ||
.then(() => expectFileToMatch('dist/polyfills.bundle.js', 'core-js')) | ||
.then(() => expectFileToMatch('dist/polyfills.bundle.js', 'zone.js')) | ||
// index.html lists the right bundles | ||
.then(() => expectFileToMatch('dist/index.html', oneLineTrim` | ||
<script type="text/javascript" src="inline.bundle.js"></script> | ||
<script type="text/javascript" src="polyfills.bundle.js"></script> | ||
`)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
is
classlist.js
meant to be referenced in 2 places? above for IE9 and here for 10 and 11