Allow defaults for @Component
metadata for Angular 2
npm install @angularclass/conventions-loader --save-dev
loader options
// default values
selectorPrefix = '';
cssExtension = '.css';
htmlExtension = '.html';
'-component' is removed from selector generated by className
{
test: /\.ts$/,
loaders: [
'ts-loader',
'@angularclass/conventions-loader'
]
},
Given this simple Component example
app.js
@Component({})
export class App {
}
Webpack will change the code
app.js
@Component({
selector: "app",
styles: [require("./app.css")],
template: require("./app.html")
})
export class App {
}
this is assuming you have corresponding files next to the component. You may overwrite the selector at anytime by providing one. If the selector and the component file name does not match then the corresponding css/template file with the selector will be injected.
Sean Larkin from the Webpack team TheLarkInn/angular2-template-loader
enjoy — AngularClass
Learn AngularJS, Angular 2, and Modern Web Development from the best. Looking for corporate Angular training, want to host us, or Angular consulting? [email protected]
Apache-2.0