Baseado em angular/angular-cli#2688
For anyone needs a way to achieve this goal through angular-cli, please have a look here: softdays/angularcli-index-location@c9918fd
Key steps
npm i -D @angular-builders/custom-webpack
angular.json > projects > your-project-name > architect > build > replace builder value by:
"builder": "@angular-builders/custom-webpack:browser"
angular.json > projects > your-project-name > architect > build > options > outputPath:
Prepend output path with your subfolder, i.e. "outputPath": "dist/app"
angular.json > projects > your-project-name > architect > build > options, add:
"customWebpackConfig": {
"path": "./extra-webpack.config.js",
"replaceDuplicatePlugins": true
}`
angular.json > projects > your-project-name > architect > build > configurations, add:
"deployUrl": "app/",
"baseHref": "",
Create extra-webpack.config.js file at project root with the content below:
const fs = require('fs');
module.exports = (config, options) => {
config.plugins.push({
apply: (compiler) => {
compiler.hooks.afterEmit.tap('MyAfterEmitPlugin', (compilation) => {
// Replace 'app' path below with your subfolder path
fs.renameSync('./dist/app/index.html', './dist/index.html');
fs.renameSync('./dist/app/favicon.ico', './dist/favicon.ico');
});
}
});
return config;
};