I am having trouble creating a starter project with Angular (4.4.4
) and Webpack (3.6.0
). My configuration is working with AOT build and template
declaration in my component
, but as soon as I add a html template (and replace template
with templateUrl
) Webpack comes into an infinite loop and gets stuck at 95% emtitting
. I am using html-loader V0.5.1
for the template loading
webpack.common.js
module.exports = {
entry: {
app: './src/main.ts',
vendor: getVendorPackages()
},
output: {
path: __dirname + '/dist',
filename: "app.bundle.js"
},
module: {
loaders: [
{
test: /\.ts$/,
loaders: ['awesome-typescript-loader', 'angular2-template-loader']
},
{
test: /\.html$/,
loader: 'html-loader'
}
]
},
plugins: [
new webpack.ContextReplacementPlugin( //Resolve Angular warnings
/angular(\\|\/)core(\\|\/)@angular/,
path.resolve(__dirname, '../src')
),
new webpack.optimize.CommonsChunkPlugin({ //Create secondary bundle containing dependencies
name: 'vendor',
filename: 'vendor.bundle.js',
minChunks(module) {
const context = module.context;
return context && context.indexOf('node_modules') >= 0;
},
}),
new htmlWebpackPlugin({ //Generate index.html
template: './src/index.html'
}),
new webpack.ContextReplacementPlugin( //Only export the locals we need | https://github.com/moment/moment/issues/2517
/moment[\/\\]locale$/, /en|nl/
)
],
resolve: {
extensions: ['.js', '.ts']
}
};
app.component.ts
import {Component} from '@angular/core';
@Component({
selector: 'hn-root',
// template: `<h1>Hello world</h1>`
templateUrl: 'app.html',
// styleUrls: ['./app.scss']
})
export class AppComponent {
}
app.html
<h1>Hello big world</h1>
package.json
{
"name": "angular-webpack-starter",
"version": "0.1.0",
"scripts": {
"build": "webpack --config webpack.dev.js",
"serve": "webpack-dev-server --config webpack.dev.js",
"build --prod": "webpack -p --config webpack.prod.js --progress"
},
"dependencies": {
"@angular/common": "4.4.4",
"@angular/compiler": "4.4.4",
"@angular/core": "4.4.4",
"@angular/forms": "4.4.4",
"@angular/http": "4.4.4",
"@angular/platform-browser": "4.4.4",
"@angular/platform-browser-dynamic": "4.4.4",
"@angular/router": "4.4.4",
"core-js": "2.5.1",
"reflect-metadata": "0.1.10",
"rxjs": "5.4.3",
"zone.js": "0.8.18"
},
"devDependencies": {
"@angular/compiler-cli": "4.4.4",
"@ngtools/webpack": "1.7.2",
"@types/core-js": "0.9.43",
"@types/node": "8.0.31",
"angular2-template-loader": "0.6.2",
"awesome-typescript-loader": "3.2.3",
"codelyzer": "3.2.0",
"html-loader": "0.5.1",
"html-webpack-plugin": "2.30.1",
"tslint": "5.7.0",
"typescript": "2.5.3",
"webpack": "3.6.0",
"webpack-bundle-analyzer": "2.9.0",
"webpack-dev-server": "2.9.1",
"webpack-merge": "4.1.0"
}
}
I am clearly doing something wrong, but I cannot figure out what that is..
I've tried
Changing
templateUrl
into './app.html'Changing
app.html
intoapp.component.html
(angular convention)Changing
loaders:[angular2-template-loader]
toloaders:[angular2-template-loader?keepUrl=true]
I also checked the webpack.config.js of most angular starters (including angular-cli) and they are using raw-loader
instead of html-loader
. Makes me wondering, can html-loader
be used in combination with AOT compilation
, since it creates inline html?