On Windows you can use type
instead of cat
and follow a similar approach proposed by @Milad:
1: Extend the scripts in package.json
"build-prod": "ng build --prod --output-hashing=none",
"package-es5": "cd dist/app-name && type runtime-es5.js polyfills-es5.js main-es5.js > bundle-es5.js",
"package-es2015": "cd dist/app-name && type runtime-es2015.js polyfills-es2015.js main-es2015.js > bundle-es2015.js",
"bundle": "npm run build-prod app-name && npm run package-es5 && npm run package-es2015",
2: Run the bundling process
npm run bundle
3: Replace the scripts automatically added in index.html
manually
<script src="bundle-es2015.js" type="module"></script>
<script src="bundle-es5.js" nomodule defer></script>
To overcome the manual step, I'm using the following workaround:
1: Create an empty placeholder.html
in the same folder as index.html
2: Copy the index.html
file and rename it to index.prod.html
2: Modify index.prod.html
with static stylesheet
and scripts
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>app-name</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="styles.css"></head>
</head>
<body>
<app-root></app-root>
<script src="bundle-es2015.js" type="module"></script>
<script src="bundle-es5.js" nomodule defer></script>
</body>
</html>
4: Add index.html
to the assets array in angular.json
"app-name": {
"architect": {
"build": {
"options": {
"assets": [
"projects/app-name/src/index.html",
...
],
5: Modify the index entry in angular.json
to point to placeholder.html
and replace index.html
with index.prod.html
"app-name": {
"architect": {
"build": {
"configurations": {
"production": {
"index": "projects/app-name/src/placeholder.html",
"fileReplacements": [
{
"replace": "projects/app-name/src/index.html",
"with": "projects/app-name/src/index.prod.html"
},
...
],